Skip to content

Commit

Permalink
Support indeterminate state for boolean(checkbox) cfs
Browse files Browse the repository at this point in the history
Both checked/unchecked states update boolean custom fields, so we need an
indeterminate state to do nothing for pages like bulk update page.
  • Loading branch information
sunnavy committed Feb 6, 2024
1 parent 88f7683 commit 589138d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion share/html/Elements/EditCustomFieldSelect
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,24 @@
<div class="custom-control custom-checkbox">
<input id="<% $name . '-Display' %>" type="checkbox" class="custom-control-input" data-checked-value="<% $TrueValue %>" data-unchecked-value="<% $FalseValue %>" value-target="#<% $name %>" <% $isChecked ? "checked" : "" %> />
<label class="custom-control-label" for="<% $name . '-Display' %>"></label>
<input type="hidden" id="<% $name %>" name="<% $name %>" class="custom-control" value="<% $isChecked ? $TrueValue : $FalseValue %>" />
<input type="hidden" id="<% $name %>" name="<% $name %>" class="custom-control"
% if ( !$ARGS{ShowEmptyOption} ) {
value="<% $isChecked ? $TrueValue : $FalseValue %>"
% }
/>
</div>
<script type="text/javascript">
var id = <% $name |n,j %>;
id = id.replace(/:/g,'\\:');
jQuery('#' + id + '-Display').change(function() {
var target = jQuery(this).attr('id').replace(/-Display$/, '').replace(/:/g,'\\:');
jQuery('#' + target).val(jQuery(this).is(':checked') ? jQuery(this).data('checked-value') : jQuery(this).data('unchecked-value'));
jQuery('#' + target).prop('disabled', false);
});
%# Show indeterminate status for pages like bulk update to not update values by default.
% if ( $ARGS{ShowEmptyOption} ) {
jQuery('#' + id + '-Display').prop ('indeterminate', true);
% }
</script>
% } else {
% if (@category) {
Expand Down

0 comments on commit 589138d

Please sign in to comment.