Explorar el Código

#688 When the autocomplete is activated, and the allowed values depend on another value, then it is possible to set a wrong value

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2646 a333f486-631f-4898-b8df-5754b55c2be0
romainq hace 12 años
padre
commit
33adcb724b

+ 10 - 1
application/ui.extkeywidget.class.inc.php

@@ -96,7 +96,7 @@ class UIExtKeyWidget
 	}
 	
 	/**
-	 * Get the HTML fragment corresponding to the linkset editing widget
+	 * Get the HTML fragment corresponding to the ext key editing widget
 	 * @param WebPage $oP The web page used for all the output
 	 * @param Hash $aArgs Extra context arguments
 	 * @return string The HTML fragment to be inserted into the page
@@ -225,6 +225,15 @@ EOF
 			// Too many choices, use an autocomplete
 			$sSelectMode = 'false';
 		
+			// Check that the given value is allowed
+			$oSearch = $oAllowedValues->GetFilter();
+			$oSearch->AddCondition('id', $value);
+			$oSet = new DBObjectSet($oSearch);
+			if ($oSet->Count() == 0)
+			{
+				$value = 0;
+			}
+
 			if (is_null($value) || ($value == 0)) // Null values are displayed as ''
 			{
 				$sDisplayValue = isset($aArgs['sDefaultValue']) ? $aArgs['sDefaultValue'] : '';

+ 3 - 1
core/dbobjectset.class.php

@@ -272,7 +272,9 @@ class DBObjectSet
 	{
 		// Make sure that we carry on the parameters of the set with the filter
 		$oFilter = $this->m_oFilter->DeepClone();
-		$oFilter->SetInternalParams(array_merge($oFilter->GetInternalParams(), $this->m_aArgs));
+		// Note: the arguments found within a set can be object (but not in a filter)
+		// That's why PrepareQueryArguments must be invoked there
+		$oFilter->SetInternalParams(array_merge($oFilter->GetInternalParams(), MetaModel::PrepareQueryArguments($this->m_aArgs)));
 		
 		if (count($this->m_aAddedIds) == 0)
 		{

+ 1 - 1
core/expression.class.inc.php

@@ -618,7 +618,7 @@ class VariableExpression extends UnaryExpression
 		}
 		else
 		{
-			throw new MissingQueryArgument('Missing query argument', array('expecting'=>$this->m_sName, 'available'=>$aArgs));
+			throw new MissingQueryArgument('Missing query argument', array('expecting'=>$this->m_sName, 'available'=>array_keys($aArgs)));
 		}
 	}