% my $condition = $CustomField->ConditionedBy;
% if ($condition) {
% my $condition_cf = $Object->LoadCustomFieldByIdentifier($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() {
% if ($condition_cf->Type eq 'HTML') {
if (typeof CKEDITOR !== 'undefined') {
CKEDITOR.on('instanceReady', function(ev) {
var condition_cke = CKEDITOR.instances['<% $condition_name |n%>'];
% }
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%>');
% if ($condition_cf->Type eq 'HTML') {
var alternative_selector = '#cke_<% $condition_name |n%>';
alternative_selector = alternative_selector.replace(/:/g,'\\:');
% } else {
var condition_cke = 'nohtml';
var alternative_selector = '#' + '<% $condition_name |n%>'.replace(/[\W]/g, '_') + '_chosen';
% }
% if ($condition_cf->RenderType eq 'Dropdown') {
waitForElm('.dropdown.CF-<% $condition_cf->id %>-Edit').then((elm) => {
jQuery(condition_selector).triggerHandler('change');
});
% }
% if ($condition_cf->Type eq 'HTML') {
if (jQuery(alternative_selector).length) {
respondToVisibility(jQuery(alternative_selector).get(0), visible => {
% } else {
if (jQuery(condition_selector).length) {
respondToVisibility(jQuery(condition_selector).get(0), visible => {
% }
if(visible) {
% if ($condition_cf->Type eq 'HTML') {
condition_cke.fire('change');
% } else {
jQuery(condition_selector).triggerHandler('change');
% }
}
});
}
% if ($condition_cf->Type eq 'HTML') {
condition_cke.on('change', function() {
% } else {
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%>"];
% if ($condition_cf->Type eq 'HTML') {
var condition_selector_vals = Array(condition_cke.getData());
% } else {
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") || (jQuery(condition_selector).closest('form').hasClass('inline-edit') && jQuery('.inline-edit-display .custom-field-<% $condition_cf->id %>').is(':visible'))) {
condition_met = condition_is_met(condition_vals, condition_selector_vals, "<% $condition->{op} |n%>", '<% $session{CurrentUser}->LanguageHandle->language_tag %>');
}
if (condition_met) {
if (jQuery('#'+cf_id).length) {
jQuery('#'+cf_id).closest('<% $ParentSelector %>').show();
jQuery('#'+cf_id).closest('<% $ParentSelector %>').triggerHandler('show');
} else {
jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').show();
jQuery('input[name="'+cf_id+'"]').first().triggerHandler('show');
jQuery('textarea[name="'+cf_id+'"]').triggerHandler('show');
}
}
else {
if (jQuery('#'+cf_id).length) {
jQuery('#'+cf_id).closest('<% $ParentSelector %>').hide();
jQuery('#'+cf_id).closest('<% $ParentSelector %>').triggerHandler('hide');
} else {
jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').hide();
jQuery('input[name="'+cf_id+'"]').first().triggerHandler('hide');
jQuery('textarea[name="'+cf_id+'"]').triggerHandler('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).closest('<% $ParentSelector %>').triggerHandler('hide');
} else {
jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').hide();
jQuery('input[name="'+cf_id+'"]').first().triggerHandler('hide');
jQuery('textarea[name="'+cf_id+'"]').triggerHandler('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) {
if (jQuery('#'+cf_id).length) {
jQuery('#'+cf_id).closest('<% $ParentSelector %>').show();
jQuery('#'+cf_id).closest('<% $ParentSelector %>').triggerHandler('show');
} else {
jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').show();
jQuery('input[name="'+cf_id+'"]').first().triggerHandler('show');
jQuery('textarea[name="'+cf_id+'"]').triggerHandler('show');
}
}
else {
if (jQuery('#'+cf_id).length) {
jQuery('#'+cf_id).closest('<% $ParentSelector %>').hide();
jQuery('#'+cf_id).closest('<% $ParentSelector %>').triggerHandler('hide');
} else {
jQuery('input[name="'+cf_id+'"], textarea[name="'+cf_id+'"]').closest('<% $ParentSelector %>').hide();
jQuery('input[name="'+cf_id+'"]').first().triggerHandler('hide');
jQuery('textarea[name="'+cf_id+'"]').triggerHandler('hide');
}
}
});
% if ($condition_cf->RenderType eq 'List') {
jQuery(condition_selector).first().triggerHandler('change');
% } else {
% if ($condition_cf->Type eq 'HTML') {
condition_cke.fire('change');
% } else {
jQuery(condition_selector).triggerHandler('change');
% }
% }
% if ($condition_cf->Type eq 'HTML') {
});
}
% }
});
</script>
% }
% }
<%ARGS>
$CustomField
$Object
$Grouping => undef
$ParentSelector => 'tr'
</%ARGS>