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

allowMismatch only works if user does not select an option first #13

Open
DODMax opened this issue Feb 7, 2012 · 1 comment
Open

allowMismatch only works if user does not select an option first #13

DODMax opened this issue Feb 7, 2012 · 1 comment

Comments

@DODMax
Copy link

DODMax commented Feb 7, 2012

When allowMismatch is enabled, if the user first selects an option and then enter a custom value the value of the first selected item is still associated to the field name.
It is therefore not possible to know if the user entered a custom value or picked from the list.

More info:
Option list looks like that B
$_POST['select'] => A (last option selected, even if custom value entered)
$_POST['new_select'] => B (literal value of the option, even if an option has been selected from the list)

@DODMax
Copy link
Author

DODMax commented Feb 8, 2012

Actually I figured something out (the code is really clear, cheers!)
I just changed the keyup function as below.
This way when something is typed in the input the select value is cleared.
Now we can tell by looking at the post values if user chose an option or typed a custom value.

The default action of the keyup event now looks like this:

this.input.keyup(function(event) {
[...]
default:
self.filterResults();
if (self.settings.allowMismatch)
self.hidden.val(""); //added: clear hidden field value when typing
break;
}

I guess it would be better to avoid the if at each keyup and just do

self.hidden.val("");
self.picked = false;

and let the reset function do the work on focus out but the hidden field value needs to be rolled back there too and I'm not sure how to do that.

colbysargentcodes pushed a commit to colbysargentcodes/jquery-flexselect that referenced this issue Apr 13, 2017
Line 315:
Change setValue.val(""); to setValue(""); This will now set original
select's value to blank as intended. Previously this would have no
effect and instead kept previously selected values.
Fixes issues rmm5t#13 and rmm5t#37.
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

1 participant