diff --git a/datamodels/2.x/itop-portal-base/portal/web/css/portal.scss b/datamodels/2.x/itop-portal-base/portal/web/css/portal.scss index d2e9d10dd..e8c2b2809 100644 --- a/datamodels/2.x/itop-portal-base/portal/web/css/portal.scss +++ b/datamodels/2.x/itop-portal-base/portal/web/css/portal.scss @@ -893,7 +893,7 @@ table .group-actions .item-action-wrapper .panel-body > p:last-child{ border: 1px solid $gray-lighter; } .form_field.has-error div.cke{ - border: 1px solid $state-danger-border; + border: 1px solid $state-danger-text; border-radius: $border-radius-base; box-shadow: inset 0 1px 1px rgba(0,0,0,0.075); } diff --git a/js/form_field.js b/js/form_field.js index 6f33ead5a..7d715e7b9 100644 --- a/js/form_field.js +++ b/js/form_field.js @@ -142,6 +142,11 @@ $(function() oResult.is_valid = false; oResult.error_messages.push(this.options.validators.mandatory.message); } + // ... Field empty but not mandatory, no need to validate + else if( bEmpty && !bMandatory ) + { + // It's okay, no need to validate + } // ... Otherwise, we check every validators else { diff --git a/sources/form/field/field.class.inc.php b/sources/form/field/field.class.inc.php index 5c0ac1b6b..87672649f 100644 --- a/sources/form/field/field.class.inc.php +++ b/sources/form/field/field.class.inc.php @@ -393,12 +393,18 @@ abstract class Field { $this->SetValid(true); $this->EmptyErrorMessages(); - foreach ($this->GetValidators() as $oValidator) + + $bEmpty = ( ($this->GetCurrentValue() === null) || ($this->GetCurrentValue() === '') ); + + if (!$bEmpty || $this->GetMandatory()) { - if (!preg_match($oValidator->GetRegExp(true), $this->GetCurrentValue())) + foreach ($this->GetValidators() as $oValidator) { - $this->SetValid(false); - $this->AddErrorMessage($oValidator->GetErrorMessage()); + if (!preg_match($oValidator->GetRegExp(true), $this->GetCurrentValue())) + { + $this->SetValid(false); + $this->AddErrorMessage($oValidator->GetErrorMessage()); + } } }