I’m using the jQueryUI combobox. If the user enters a string that isn’t an option in the select element it creates a new option element with that value. The problem is that it currently prepends ‘undefined’ the the value that was entered. How could I remove the ‘undefined’ substring before it submits? Here’s the code:
change: function(event, ui) {
if (!ui.item) {
var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i"),
valid = false;
select.children("option").each(function() {
if ($(this).text().match(matcher)) {
this.selected = valid = true;
return false;
}
});
if (!valid) {
new_value = self.options.precede_new_with + $(this).val();
option = $('<option value="' + new_value + '">' + $(this).val() + '</option>');
select.append(option);
select.val(new_value);
return false;
}
}
}
it appears the problem is that self.options.precede_new_with is returning ‘undefined’.