瀏覽代碼

Customers portal : Fixed a bug in UserRequest edition form that prevented user to submit. Validation method was returning false on reoslution_code. Fix was to not check validators on empty && none mandatory fields (on both client and server sides).

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4265 a333f486-631f-4898-b8df-5754b55c2be0
glajarige 9 年之前
父節點
當前提交
52ec520b23

+ 1 - 1
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);
 }

+ 5 - 0
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
 				{

+ 10 - 4
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());
+				}
 			}
 		}