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

Clearing value of dependent fields #79

Closed
tyctor opened this issue Sep 2, 2021 · 3 comments
Closed

Clearing value of dependent fields #79

tyctor opened this issue Sep 2, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@tyctor
Copy link

tyctor commented Sep 2, 2021

Clearing value of dependent fields not working for multiple dependent fields

for me this selector will not match if there are multiple field names

$('[data-select2-dependent-fields=' + name + ']').each(function () {
          $(this).val('').trigger('change')
})

what is working for me is to change it like this

$("[data-select2-dependent-fields~='" + name + "']").each(function () {
          $(this).val('').trigger('change')
})
@tyctor tyctor added the bug Something isn't working label Sep 2, 2021
@codingjoe
Copy link
Owner

Hi @tyctor,
Thank you for reaching out. This could be related to spaces in the data value.
Can you try with quotation marks but without the tilde? Anyhow, if you have a working solution, please don't hesitate to open a pull-request, I would very much welcome the contribution.
Best
Joe

@codingjoe codingjoe assigned tyctor and unassigned codingjoe Sep 16, 2021
@quevon24
Copy link

quevon24 commented Apr 29, 2022

Having same issue, as @tyctor said, with this change now works fine:

$('[data-select2-dependent-fields~=' + name + ']').each(function () {
  $(this).val('').trigger('change')
})

@codingjoe
Copy link
Owner

Thanks @quevon24, that's good feedback. Now someone just needs to find time to turn it into a patch. Maybe you'd be intersted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants