jquery-flexselect icon indicating copy to clipboard operation
jquery-flexselect copied to clipboard

allowMismatch only works if user does not select an option first

Open DODMax opened this issue 13 years ago • 1 comments

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 $_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 avatar Feb 07 '12 11:02 DODMax

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.

DODMax avatar Feb 08 '12 07:02 DODMax