Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable clearing of dependent fields #81

Open
tyctor opened this issue Sep 3, 2021 · 1 comment
Open

Configurable clearing of dependent fields #81

tyctor opened this issue Sep 3, 2021 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@tyctor
Copy link

tyctor commented Sep 3, 2021

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')
@codingjoe codingjoe added the enhancement New feature or request label Sep 16, 2021
@codingjoe
Copy link
Owner

@tyctor great idea for an enhancement. I'd certainly welcome a contribution here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants