N°984 Portal: Fix autocomplete field reset when changing value of parent field in request templates.

SVN:trunk[5261]
This commit is contained in:
Guillaume Lajarige
2018-01-16 15:37:28 +00:00
parent 1926a40277
commit 9d76ac96bc
2 changed files with 35 additions and 18 deletions

View File

@@ -19,8 +19,12 @@
namespace Combodo\iTop\Form\Field;
use \Closure;
use \DBSearch;
use Closure;
use DBSearch;
use DBObjectSet;
use BinaryExpression;
use FieldExpression;
use ScalarExpression;
use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator;
/**
@@ -148,4 +152,26 @@ class SelectObjectField extends Field
{
return $this->sSearchEndpoint;
}
/**
* Resets current value is not among allowed ones.
* By default, reset is done ONLY when the field is not read-only.
*
* @param boolean $bAlways Set to true to verify even when the field is read-only.
*/
public function VerifyCurrentValue($bAlways = false)
{
if(!$this->GetReadOnly() || $bAlways)
{
$oValuesScope = $this->GetSearch()->DeepClone();
$oBinaryExp = new BinaryExpression(new FieldExpression('id', $oValuesScope->GetClassAlias()), '=', new ScalarExpression($this->currentValue));
$oValuesScope->AddConditionExpression($oBinaryExp);
$oValuesSet = new DBObjectSet($oValuesScope);
if($oValuesSet->Count() === 0)
{
$this->currentValue = null;
}
}
}
}