소스 검색

Support several sets of forbidden values (with a specific "reason" message) per field.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3500 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 10 년 전
부모
커밋
922ca2e819
2개의 변경된 파일14개의 추가작업 그리고 15개의 파일을 삭제
  1. 6 10
      application/forms.class.inc.php
  2. 8 5
      js/property_field.js

+ 6 - 10
application/forms.class.inc.php

@@ -867,13 +867,11 @@ class DesignerTextField extends DesignerFormField
 {
 	protected $sValidationPattern;
 	protected $aForbiddenValues;
-	protected $sExplainForbiddenValues;
 	public function __construct($sCode, $sLabel = '', $defaultValue = '')
 	{
 		parent::__construct($sCode, $sLabel, $defaultValue);
 		$this->sValidationPattern = '';
-		$this->aForbiddenValues = null;
-		$this->sExplainForbiddenValues = null;
+		$this->aForbiddenValues = array();
 	}
 	
 	public function SetValidationPattern($sValidationPattern)
@@ -883,17 +881,17 @@ class DesignerTextField extends DesignerFormField
 
 	public function SetForbiddenValues($aValues, $sExplain)
 	{
-		$this->aForbiddenValues = $aValues;
+		$aForbiddenValues = $aValues;
 		
 		$iDefaultKey = array_search($this->defaultValue, $this->aForbiddenValues);
 		if ($iDefaultKey !== false)
 		{
 			// The default (current) value is always allowed...
-			unset($this->aForbiddenValues[$iDefaultKey]);
+			unset($aForbiddenValues[$iDefaultKey]);
 			
 		}
 		
-		$this->sExplainForbiddenValues = $sExplain;
+		$this->aForbiddenValues[] = array('values' => $aForbiddenValues, 'message' => $sExplain);
 	}
 	
 	public function Render(WebPage $oP, $sFormId, $sRenderMode='dialog')
@@ -911,17 +909,15 @@ class DesignerTextField extends DesignerFormField
 			if (is_array($this->aForbiddenValues))
 			{
 				$sForbiddenValues = json_encode($this->aForbiddenValues);
-				$sExplainForbiddenValues = addslashes($this->sExplainForbiddenValues);
 			}
 			else
 			{
-				$sForbiddenValues = 'null';
-				$sExplainForbiddenValues = 'null';
+				$sForbiddenValues = '[]'; //Empty JS array
 			}
 			$sMandatory = $this->bMandatory ? 'true' :  'false';
 			$oP->add_ready_script(
 <<<EOF
-$('#$sId').bind('change keyup validate', function() { ValidateWithPattern('$sId', $sMandatory, '$sPattern', $(this).closest('form').attr('id'), $sForbiddenValues, '$sExplainForbiddenValues'); } );
+$('#$sId').bind('change keyup validate', function() { ValidateWithPattern('$sId', $sMandatory, '$sPattern', $(this).closest('form').attr('id'), $sForbiddenValues); } );
 {
 	var myTimer = null;
 	$('#$sId').bind('keyup', function() { clearTimeout(myTimer); myTimer = setTimeout(function() { $('#$sId').trigger('change', {} ); }, 100); });

+ 8 - 5
js/property_field.js

@@ -466,7 +466,7 @@ $(function()
 
 var oFormValidation = {};
 
-function ValidateWithPattern(sFieldId, bMandatory, sPattern, sFormId, aForbiddenValues, sExplainForbiddenValues)
+function ValidateWithPattern(sFieldId, bMandatory, sPattern, sFormId, aForbiddenValues)
 {
 	var currentVal = $('#'+sFieldId).val();
 	var bValid = true;
@@ -485,11 +485,14 @@ function ValidateWithPattern(sFieldId, bMandatory, sPattern, sFormId, aForbidden
 	{
 		for(var i in aForbiddenValues)
 		{
-			if (aForbiddenValues[i] == currentVal)
+			for(j in aForbiddenValues[i].values)
 			{
-				bValid = false;
-				sMessage = sExplainForbiddenValues;
-				break;
+				if (aForbiddenValues[i].values[j] == currentVal)
+				{
+					bValid = false;
+					sMessage = aForbiddenValues[i].message;
+					break;	
+				}
 			}
 		}
 	}