mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Added the validation of mandatory form fields before submitting the creation / modification / clone forms.
SVN:trunk[140]
This commit is contained in:
@@ -57,8 +57,11 @@ function ReloadObjectFromServer(sJSON)
|
||||
function GoToStep(iCurrentStep, iNextStep)
|
||||
{
|
||||
var oCurrentStep = document.getElementById('wizStep'+iCurrentStep);
|
||||
oCurrentStep.style.display = 'none';
|
||||
ActivateStep(iNextStep);
|
||||
if (CheckMandatoryFields('wizStep'+iCurrentStep))
|
||||
{
|
||||
oCurrentStep.style.display = 'none';
|
||||
ActivateStep(iNextStep);
|
||||
}
|
||||
}
|
||||
|
||||
function ActivateStep(iTargetStep)
|
||||
@@ -104,3 +107,39 @@ function AjaxGetDefaultValue(oObj, sClass, sAttCode, iFieldId)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function CheckMandatoryFields(sFormId)
|
||||
{
|
||||
$('#'+sFormId+' :submit').attr('disable', 'disabled');
|
||||
$('#'+sFormId+' :button[type=submit]').attr('disable', 'disabled');
|
||||
firstErrorId = '';
|
||||
|
||||
var iErrorsCount = 0;
|
||||
$('#'+sFormId+' :input.mandatory').each( function() {
|
||||
if (( this.value == '') || (this.value == 0))
|
||||
{
|
||||
this.style.background = '#fcc';
|
||||
iErrorsCount++;
|
||||
if (iErrorsCount == 1)
|
||||
{
|
||||
firstErrorId = this.id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.style.background = '#fff';
|
||||
}
|
||||
}
|
||||
);
|
||||
if(iErrorsCount > 0)
|
||||
{
|
||||
alert('Please fill-in all mandatory fields before continuing.');
|
||||
$('#'+sFormId+' :submit').attr('disable', '');
|
||||
$('#'+sFormId+' :button[type=submit]').attr('disable', '');
|
||||
if (firstErrorId != '')
|
||||
{
|
||||
$('#'+firstErrorId).focus();
|
||||
}
|
||||
}
|
||||
return(iErrorsCount == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user