Fixed Trac #307: prevent form submission when the value typed into an autocomplete field does not correspond to a valid value.

SVN:trunk[930]
This commit is contained in:
Denis Flaven
2010-10-26 08:12:31 +00:00
parent 05a2443afe
commit 0b95b3799e
3 changed files with 30 additions and 3 deletions

View File

@@ -154,7 +154,11 @@ function ValidateField(sFieldId, sPattern, bMandatory, sFormId, nullValue)
{
var bValid = true;
var currentVal = $('#'+sFieldId).val();
if (bMandatory && (currentVal == nullValue))
if (currentVal == '$$NULL$$') // Convention to indicate a non-valid value since it may have to be passed as text
{
bValid = false;
}
else if (bMandatory && (currentVal == nullValue))
{
bValid = false;
}
@@ -248,3 +252,26 @@ function ValidatePasswordField(id, sFormId)
$('#v_'+id).html(''); //<img src="../images/validation_ok.png" />');
return true;
}
// Called when filling an autocomplete field
function OnAutoComplete(id, event, data, formatted)
{
if (data)
{
// A valid match was found: data[0] => label, data[1] => value
$('#'+id).val(data[1]);
$('#'+id).trigger('change');
}
else
{
if ($('#label_'+id).val() == '')
{
$('#'+id).val(''); // Empty value
}
else
{
$('#'+id).val('$$NULL$$'); // Convention: not a valid value
}
$('#'+id).trigger('change');
}
}