Disallow Invalid Values

Mar 31, 2011 at 4:36 PM
Hi, I have added in the functionality for forcing the value entered in the input control to be a value returned from the query. This is pretty simplistic, it just re-selects the input if the value is invalid, but it could be altered to raise a callback for displaying modal pop-up.

First add an option:

allowEdit: true, // set to true to force the value in the input to be a value of the data results; setting to false will only provide a hint for selection.
Now add a class variable at the top section where the other var's are declared. The variable will be used to store the validity of the input box:
isValid = o.allowEdit 
In the onblur of the $input setup chain add the following:
if (!o.allowEdit) {
  setTimeout(function () { if (!isValid) { $input.select(); } }, 150);
In the callback function add the following after var totalResults:
isValid = totalResults === 1; 
And finally in the settCurr function add directly after 'if ($curr)':
isValid = true;