You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:自定义下拉选项自动填充并隐藏工单主题栏功能异常排查

问题排查与修复方案

核心问题分析

你当前代码的问题在于仅在页面加载时获取一次下拉框的值,此时用户还未选择任何选项,subject_value始终是空值,提交时自然无法填充有效内容;同时没有监听下拉框的选择变化,无法实时同步选中值。


修复方案一:实时监听下拉框变化

// Hide Subject and auto populate with custom field dropdown selection
$(document).ready(function () {
    var ticketForm = location.search.split('ticket_form_id=')[1];
    let subject_value = '';

    if (ticketForm == 123456789) {
        $('#request_subject').parent('.request_subject').hide();

        // 监听下拉框选择变化,实时更新主题值
        $('.request_custom_fields_987654321').on('change', function() {
            subject_value = $(this).val();
        });

        // 提交表单时填充最新选中值
        $("#new_request").submit(function(e) {
            $('#request_subject').val(subject_value);
        });
    }
})

修复方案二:提交时直接获取当前值(更简洁)

// Hide Subject and auto populate with custom field dropdown selection
$(document).ready(function () {
    var ticketForm = location.search.split('ticket_form_id=')[1];

    if (ticketForm == 123456789) {
        $('#request_subject').parent('.request_subject').hide();

        // 提交时直接拉取下拉框当前选中值
        $("#new_request").submit(function(e) {
            const selectedValue = $('.request_custom_fields_987654321').val();
            $('#request_subject').val(selectedValue);
        });
    }
})

内容的提问来源于stack exchange,提问作者Noelle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 23:03:18