django-select2 icon indicating copy to clipboard operation
django-select2 copied to clipboard

Use dependent_fields with checkbox

Open codingjoe opened this issue 1 year ago • 0 comments

Discussed in https://github.com/codingjoe/django-select2/discussions/282

Originally posted by CleitonDeLima May 29, 2024 If include a field checkbox in dependent_fields, the 'on' value is sent to the view regardless of whether the field is checked or not.

This behavior can be changed here

$.each(dependentFields, function (i, dependentField) {
  var field = $("[name=" + dependentField + "]", $element.closest("form"));
  if (field.is(":checkbox")) {
    result[dependentField] = field.prop("checked");
  } else {
    result[dependentField] = field.val();
  }
});

codingjoe avatar Jul 02 '24 08:07 codingjoe