namespace Combodo\iTop\Form\Field; use \Closure; use \DBSearch; use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator; /** * Description of SelectObjectField * */ class SelectObjectField extends Field { protected $oSearch; protected $iMaximumComboLength; protected $iMinAutoCompleteChars; protected $iControlType; const CONTROL_SELECT = 1; const CONTROL_RADIO_VERTICAL = 2; public function __construct($sId, Closure $onFinalizeCallback = null) { parent::__construct($sId, $onFinalizeCallback); $this->oSearch = null; $this->iMaximumComboLength = null; $this->iMinAutoCompleteChars = 3; $this->iControlType = self::CONTROL_SELECT; } public function SetSearch(DBSearch $oSearch) { $this->oSearch = $oSearch; } public function SetMaximumComboLength($iMaximumComboLength) { $this->iMaximumComboLength = $iMaximumComboLength; } public function SetMinAutoCompleteChars($iMinAutoCompleteChars) { $this->iMinAutoCompleteChars = $iMinAutoCompleteChars; } public function SetControlType($iControlType) { $this->iControlType = $iControlType; } /** * Sets if the field is mandatory or not. * Setting the value will automatically add/remove a MandatoryValidator to the Field * * @param boolean $bMandatory * @return \Combodo\iTop\Form\Field\Field */ public function SetMandatory($bMandatory) { // Before changing the property, we check if it was already mandatory. If not, we had the mandatory validator if ($bMandatory && !$this->bMandatory) { $this->AddValidator(new NotEmptyExtKeyValidator()); } if (!$bMandatory) { foreach ($this->aValidators as $iKey => $oValue) { if ($oValue::Getname() === NotEmptyExtKeyValidator::GetName()) { unset($this->aValidators[$iKey]); } } } $this->bMandatory = $bMandatory; return $this; } public function GetSearch() { return $this->oSearch; } public function GetMaximumComboLength() { return $this->iMaximumComboLength; } public function GetMinAutoCompleteChars() { return $this->iMinAutoCompleteChars; } public function GetControlType() { return $this->iControlType; } }