mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
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:
@@ -1128,7 +1128,7 @@ EOF
|
||||
$sHTMLValue .= "<input type=\"hidden\" id=\"$iId\" name=\"attr_{$sFieldPrefix}{$sAttCode}{$sNameSuffix}\" value=\"$value\" />\n";
|
||||
$oPage->add_ready_script("\$('#label_$iId').autocomplete('./ajax.render.php', { scroll:true, minChars:3, onItemSelect:selectItem, onFindValue:findValue, formatItem:formatItem, autoFill:true, keyHolder:'#$iId', extraParams:{operation:'autocomplete', sclass:'$sClass',attCode:'".$sAttCode."'}});");
|
||||
$oPage->add_ready_script("\$('#label_$iId').blur(function() { $(this).search(); } );");
|
||||
$oPage->add_ready_script("\$('#label_$iId').result( function(event, data, formatted) { if (data) { $('#{$iId}').val(data[1]); $('#{$iId}').trigger('change'); } else { $('#{$iId}').val(''); $('#{$iId}').trigger('change');} } );");
|
||||
$oPage->add_ready_script("\$('#label_$iId').result( function(event, data, formatted) { OnAutoComplete('$iId', event, data, formatted); } );");
|
||||
$aEventsList[] ='change';
|
||||
}
|
||||
else
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
}
|
||||
|
||||
.ac_loading {
|
||||
background: white url('indicator.gif') right center no-repeat;
|
||||
background: white url('../images/indicator.gif') right center no-repeat;
|
||||
}
|
||||
|
||||
.ac_odd {
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user