Index: includes/forminputs/SF_TextWithAutocompleteInput.php =================================================================== --- includes/forminputs/SF_TextWithAutocompleteInput.php (revision 104239) +++ includes/forminputs/SF_TextWithAutocompleteInput.php (working copy) @@ -176,6 +176,9 @@ if ( array_key_exists( 'placeholder', $other_args ) ) { $inputAttrs['placeholder'] = $other_args['placeholder']; } + if ( array_key_exists( 'existing values only', $other_args ) ) { + $inputAttrs['existingvaluesonly'] = 'true'; + } $text = "\n\t" . Xml::element( 'input', $inputAttrs ) . "\n"; if ( array_key_exists( 'uploadable', $other_args ) && $other_args['uploadable'] == true ) { @@ -224,6 +227,12 @@ public static function getParameters() { $params = parent::getParameters(); $params = array_merge( $params, self::getAutocompletionParameters() ); + $params[] = array( + 'name' => 'existing values only', + 'type' => 'boolean', + 'description' => wfMsg( 'sf_forminputs_existingvaluesonly' ) + ); + return $params; } Index: libs/SemanticForms.js =================================================================== --- libs/SemanticForms.js (revision 104239) +++ libs/SemanticForms.js (working copy) @@ -475,6 +475,14 @@ if (isEmpty) { this.addErrorMessage(sfgBlankErrorStr); return false; + } else if (this.find("input").attr("existingvaluesonly") == 'true'){ + var settings = this.find("input").attr("autocompletesettings"); + var isValueExist = (jQuery.inArray(this.find("input").val(), sfgAutocompleteValues[settings]) != -1); + if (!isValueExist) { + this.addErrorMessage(sfgBlankErrorStr); + return false; + } + return true; } else { return true; } @@ -484,6 +492,13 @@ if (this.find("input").val() == '') { this.addErrorMessage(sfgBlankErrorStr); return false; + } else if (this.find("select").attr("existingvaluesonly") == 'true') { + var isValueExist = (this.find("select").find("[value='" + this.find("input").val() + "']").size() != 0); + if (!isValueExist) { + this.addErrorMessage(sfgBlankErrorStr); + return false; + } + return true; } else { return true; } @@ -901,13 +916,7 @@ }, delay: 0, change: function(event, ui) { - if (!ui.item) { - if (select.attr("existingvaluesonly") == 'true') { - // remove invalid value, as it didn't match anything - jQuery(this).val(""); - } - return false; - } + if (!ui.item) return false; select.val(ui.item.id); self._trigger("selected", event, { item: select.find("[value='" + ui.item.id + "']")