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

span text doesn't update when select box is change from the javascript #86

Open
eucalyp opened this issue Aug 7, 2014 · 3 comments
Open

Comments

@eucalyp
Copy link

eucalyp commented Aug 7, 2014

I'm using a javascript function to reset all my select option to the default one. The code to do that is pretty simple.

$('select option').prop('selected', function() { return this.defaultSelected;  });

But when I do it, the selected option is the right one in the hidden select, but in the span the text is not updated. I'm not a javascript expert, so I'm not sure if I should change the way I reset my selects or if we should fix it in your library.

Anthony

@eucalyp
Copy link
Author

eucalyp commented Aug 7, 2014

I did a little bit of research, and the problem comes from the fact that jQuery doesn't check change in attribute. So basically we would need to check change in the "selected" attribute, it would be a nice feature of the library, but it's not built-in jQuery, so we would need to add a workaround to make it works. What do you think of that?

@eucalyp
Copy link
Author

eucalyp commented Aug 7, 2014

I figured out a solution to make it works. I just trigger an event after I change the "selected" attribute of the option. So now the code is:

$('select option').prop('selected', function() { return this.defaultSelected;  });
$('select').trigger("change");

@wallaceerick
Copy link

Thanks @anbuf, good solution... save my life. 👍

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