mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-18 06:48:50 +02:00
(Retrofit from trunk) N°984 Portal: Fix autocomplete field reset when changing value of parent field in request templates.
SVN:2.4[5262]
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
|
||||
namespace Combodo\iTop\Portal\Form;
|
||||
|
||||
use Combodo\iTop\Form\Field\Field;
|
||||
use \Exception;
|
||||
use \Silex\Application;
|
||||
use \utils;
|
||||
@@ -41,6 +40,7 @@ use \AttributeDateTime;
|
||||
use \AttachmentPlugIn;
|
||||
use \Combodo\iTop\Form\FormManager;
|
||||
use \Combodo\iTop\Form\Form;
|
||||
use \Combodo\iTop\Form\Field\Field;
|
||||
use \Combodo\iTop\Form\Field\FileUploadField;
|
||||
use \Combodo\iTop\Form\Field\LabelField;
|
||||
use \Combodo\iTop\Portal\Helper\ApplicationHelper;
|
||||
@@ -715,20 +715,7 @@ class ObjectFormManager extends FormManager
|
||||
{
|
||||
// Note: We can't do this in AttributeExternalKey::MakeFormField() in the Field::SetOnFinalizeCallback() because at this point we have no information about the portal scope and ignore_silos flag, hence it always applies silos.
|
||||
// As a workaround we have to manually check if the field's current value is among the scope
|
||||
|
||||
if(!$oField->GetReadOnly())
|
||||
{
|
||||
/** @var DBObjectSearch $oValuesScope */
|
||||
$oValuesScope = $oField->GetSearch()->DeepClone();
|
||||
$oBinaryExp = new BinaryExpression(new FieldExpression('id', $oValuesScope->GetClassAlias()), '=', new ScalarExpression($oField->GetCurrentValue()));
|
||||
$oValuesScope->AddConditionExpression($oBinaryExp);
|
||||
$oValuesSet = new DBObjectSet($oValuesScope);
|
||||
|
||||
if($oValuesSet->Count() === 0)
|
||||
{
|
||||
$oField->SetCurrentValue(null);
|
||||
}
|
||||
}
|
||||
$oField->VerifyCurrentValue();
|
||||
}
|
||||
// - Field that require processing on their subfields
|
||||
if (in_array(get_class($oField), array('Combodo\\iTop\\Form\\Field\\SubFormField')))
|
||||
@@ -758,6 +745,11 @@ class ObjectFormManager extends FormManager
|
||||
$oCustomField->SetSearchEndpoint($sSearchEndpoint);
|
||||
}
|
||||
}
|
||||
// - Field that require to check if the current value is among allowed ones
|
||||
if (in_array(get_class($oCustomField), array('Combodo\\iTop\\Form\\Field\\SelectObjectField')))
|
||||
{
|
||||
$oCustomField->VerifyCurrentValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1204,5 +1196,4 @@ class ObjectFormManager extends FormManager
|
||||
$oAttachment->DBDelete();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user