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

jQuery Serialize and readonly.js #19

Open
thomasb88 opened this issue Aug 18, 2022 · 1 comment
Open

jQuery Serialize and readonly.js #19

thomasb88 opened this issue Aug 18, 2022 · 1 comment

Comments

@thomasb88
Copy link

Hi Corenzan,

Looking to readonly.js, when used with select, you turn them readonly creating an input with the same name attribute than the select.

When serializing, jQuery do it using the name attribute for select, so instead having no value (serializeArray don't get value when the element is disabled), you get the value from this hidden input.

But when user change select value when select element is disabled, identifiying the select by value (in case of programmaticaly change without direct user interaction), then it turns that this hidden input is not update.

The idea would perhaps to set a trigger that update this hidden input value when the select value is modified on readonly mode.

What do you think ?

@haggen
Copy link
Member

haggen commented Aug 18, 2022

Hello @thomasb88. 👋

It does make sense and it's already possible to update the surrogate input after programmatically changing the value of the select by dispatching a change event on the select.

const select = $("select");

select
  .readonly() // Make it read only.
  .val("A different value") // Change its value via JS.
  .trigger("change"); // Trigger change event. This will update the surrogate input.

Let me know if this solves your problem. :)

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

No branches or pull requests

2 participants