I have another related question.
The question has two parts.
The first, is it possible to have a list delimitered by "AND" with JS?
If so, how do changed the following line
return split( term ).pop();
into a similar one that uses the "AND" delimiter?
A quick look at split function does not help me with it.
Many thanks.
HTML
<input type="text" name="testme2" value="some stuff here2," class="vest2" size="110">
JS and jQuery
$(function() {
var vList = ["An Unmarried Woman" AND "A Single Man" AND "Married Couple" AND "A Married Couple With Joint Tenancy" AND "Husband And Wife"];
function split( val ) {
return val.split( /AND\s*/ );
}
function extractLast( term ) {
return split( term ).pop();
// how to add list delimiter of "AND" above?
}
$(".vest2")
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(
vList, extractLast( request.term ) ) );
},
focus: function() {
// prevent value inserted on focus
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
// terms.push( "" );
this.value = terms.join( "AND " );
return false;
}
});
});