Skip to content

Configurable clearing of dependent fields #81

Description

@tyctor

it would be nice to have configurable clearing of dependent field on various events

by now only select event is clearing dependent fields

$element.on('select2:select', function (e) {

in my use case i need to clear also on unselect and clear events
so i added code

      $element.on('select2:clear', function (e) {
        var name = $(e.currentTarget).attr('name')
        $("[data-select2-dependent-fields~='" + name + "']").each(function () {
          $(this).val('').trigger('change')
        })
      })
      $element.on('select2:unselect', function (e) {
        var name = $(e.currentTarget).attr('name')
        $("[data-select2-dependent-fields~='" + name + "']").each(function () {
          $(this).val('').trigger('change')
        })
      })

but probably better is to have this some how configurable
for example by adding to django settings something like

SELECT2_CLEAR_ON_EVENTS = ('select', 'clear', 'unselect')

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions