%   my $condition = $CustomField->ConditionedBy;
%   if ($condition) {
%       my $condition_cf = RT::CustomField->new($session{CurrentUser});
%       $condition_cf->Load($condition->{CF});
%       if ($condition_cf->id) {
%           my $condition_val = $condition->{vals} || '';
%           my @condition_vals = ref($condition_val) eq 'ARRAY' ? @$condition_val : ($condition_val);
%           my ($cf_id, $condition_grouping, $condition_name);
%           my $request_path = $HTML::Mason::Commands::r->path_info;
%           my $selfservice_cf_groupings = RT->Config->Get('SelfServiceCustomFieldGroupings') || 0;
%           if ($request_path =~ qr{^/SelfService/(Create|Update)\.html} && !$selfservice_cf_groupings) {
%               $cf_id = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField);
%               $condition_name = GetCustomFieldInputName(Object => $Object, CustomField => $condition_cf);
%            } else {
%               $Grouping =~ s/\W//g if $Grouping;
%               $cf_id = GetCustomFieldInputName(Object => $Object, CustomField => $CustomField, Grouping => $Grouping );
%               $condition_grouping = $condition_cf->_findGrouping($Object);
%               $condition_grouping =~ s/\W//g if $condition_grouping;
%               $condition_name = GetCustomFieldInputName(Object => $Object, CustomField => $condition_cf, Grouping => $condition_grouping );
%           }
<script type="text/javascript">
jQuery(function() {
    var condition_selector = get_selector('<% $condition_name |n%>', '<% $condition_cf->Type |n%>', '<% $condition_cf->RenderType |n%>', '<% RT::Handle::cmp_version($RT::VERSION, '5.0.0') |n%>');
    var alternative_selector = '#' + '<% $condition_name |n%>'.replace(/[\W]/g, '_') + '_chosen';
    jQuery(condition_selector).change(function() {
        var cf_id = '<% $cf_id |h,n%>';
        cf_id = cf_id.replace(/:/g,'\\:');
        var condition_vals = ["<% join('", "', @condition_vals) |n%>"];
        var condition_selector_vals = get_cf_current_form_values(condition_selector, '<% $condition_cf->Type |n%>', '<% $condition_cf->RenderType |n%>', <% $condition_cf->SingleValue ? 'true' : 'false' %>);
        var condition_met = false;
        if (jQuery(condition_selector).is(':visible') || jQuery(alternative_selector).is(":visible")) {
            condition_met = condition_is_met(condition_vals, condition_selector_vals, "<% $condition->{op} |n%>", '<% $session{CurrentUser}->LanguageHandle->language_tag %>');
        }

        if (condition_met) {
            var collapse_obj;
            if (jQuery('#'+cf_id).length) {
                collapse_obj = jQuery('#'+cf_id).closest('.titlebox-content.collapse');
                jQuery('#'+cf_id).closest('<% $ParentSelector %>').show();
%           if ($condition_cf->RenderType ne 'List') {
                jQuery('#'+cf_id).trigger('show');
%           }
            } else {
                collapse_obj = jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('.titlebox-content.collapse');
                jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').show();
                jQuery('input[name="'+cf_id+'"]').first().trigger('show');
                jQuery('textarea[name="'+cf_id+'"]').trigger('show');
            }
            if (collapse_obj.length && !collapse_obj.hasClass('show')) {
                collapse_obj.collapse('show');
            }
        }
        else {
            if (jQuery('#'+cf_id).length) {
                jQuery('#'+cf_id).closest('<% $ParentSelector %>').hide();
                jQuery('#'+cf_id).trigger('hide');
            } else {
                jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').hide();
                jQuery('input[name="'+cf_id+'"]').first().trigger('hide');
                jQuery('textarea[name="'+cf_id+'"]').trigger('hide');
            }
        }
    });

    jQuery(condition_selector).closest('<% $ParentSelector %>').on('hide', function() {
        var cf_id = '<% $cf_id |h,n%>';
        cf_id = cf_id.replace(/:/g,'\\:');
        if (jQuery('#'+cf_id).length) {
            jQuery('#'+cf_id).closest('<% $ParentSelector %>').hide();
            jQuery('#'+cf_id).trigger('hide');
        } else {
            jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').hide();
            jQuery('input[name="'+cf_id+'"]').first().trigger('hide');
            jQuery('textarea[name="'+cf_id+'"]').trigger('hide');
        }
    });

    jQuery(condition_selector).closest('<% $ParentSelector %>').on('show', function() {
        var cf_id = '<% $cf_id |h,n%>';
        cf_id = cf_id.replace(/:/g,'\\:');
        var condition_vals = ["<% join('", "', @condition_vals) |n%>"];
        var condition_selector_vals = get_cf_current_form_values(condition_selector, '<% $condition_cf->Type |n%>', '<% $condition_cf->RenderType |n%>');
        var condition_met = false;
        condition_met = condition_is_met(condition_vals, condition_selector_vals, "<% $condition->{op} |n%>", '<% $session{CurrentUser}->LanguageHandle->language_tag %>');

        if (condition_met) {
            var collapse_obj;
            if (jQuery('#'+cf_id).length) {
                collapse_obj = jQuery('#'+cf_id).closest('.titlebox-content.collapse');
                jQuery('#'+cf_id).closest('<% $ParentSelector %>').show();
%           if ($condition_cf->RenderType ne 'List') {
                jQuery('#'+cf_id).trigger('show');
%           }
            } else {
                collapse_obj = jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('.titlebox-content.collapse');
                jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').show();
                jQuery('input[name="'+cf_id+'"]').first().trigger('show');
                jQuery('textarea[name="'+cf_id+'"]').trigger('show');
            }
            if (collapse_obj.length && !jQuery(collapse).hasClass('show')) {
                collapse_obj.collapse('show');
            }
        }
        else {
            if (jQuery('#'+cf_id).length) {
                jQuery('#'+cf_id).closest('<% $ParentSelector %>').hide();
                jQuery('#'+cf_id).trigger('hide');
            } else {
                jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').hide();
                jQuery('input[name="'+cf_id+'"]').first().trigger('hide');
                jQuery('textarea[name="'+cf_id+'"]').trigger('hide');
            }
        }
    });
%           if ($condition_cf->RenderType eq 'List') {
    jQuery(condition_selector).first().trigger('change');
%           } else {
    jQuery(condition_selector).trigger('change');
%           }
});
</script>
%       }
%   }
<%ARGS>
$CustomField
$Object
$Grouping => undef
$ParentSelector => 'tr'
</%ARGS>