mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°6414 Disable Field validation for untouched attcodes
This commit is contained in:
@@ -70,6 +70,12 @@ abstract class Field
|
||||
protected $sDisplayMode;
|
||||
/** @var array */
|
||||
protected $aValidators;
|
||||
/**
|
||||
* @var bool
|
||||
* @since 3.1.0 N°6414
|
||||
*/
|
||||
protected $bValidationDisabled;
|
||||
|
||||
/** @var bool */
|
||||
protected $bValid;
|
||||
/** @var array */
|
||||
@@ -96,6 +102,7 @@ abstract class Field
|
||||
$this->bMandatory = static::DEFAULT_MANDATORY;
|
||||
$this->sDisplayMode = static::DEFAULT_DISPLAY_MODE;
|
||||
$this->aValidators = array();
|
||||
$this->bValidationDisabled = false;
|
||||
$this->bValid = static::DEFAULT_VALID;
|
||||
$this->aErrorMessages = array();
|
||||
$this->onFinalizeCallback = $onFinalizeCallback;
|
||||
@@ -522,7 +529,7 @@ abstract class Field
|
||||
|
||||
/**
|
||||
* Returns if the field is editable. Meaning that it is not editable nor hidden.
|
||||
*
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function IsEditable()
|
||||
@@ -537,14 +544,35 @@ abstract class Field
|
||||
|
||||
public function OnFinalize()
|
||||
{
|
||||
if ($this->onFinalizeCallback !== null)
|
||||
{
|
||||
if ($this->onFinalizeCallback !== null) {
|
||||
// Note : We MUST have a temp variable to call the Closure. otherwise it won't work when the Closure is a class member
|
||||
$callback = $this->onFinalizeCallback;
|
||||
$callback($this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $bValidationDisabled
|
||||
*
|
||||
* @return $this
|
||||
*
|
||||
* @since 3.1.0 N°6414
|
||||
*/
|
||||
public function SetValidationDisabled(bool $bValidationDisabled = true): Field
|
||||
{
|
||||
$this->bValidationDisabled = $bValidationDisabled;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function IsValidationDisabled(): bool
|
||||
{
|
||||
return $this->bValidationDisabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the validators to see if the field's current value is valid.
|
||||
* Then sets $bValid and $aErrorMessages.
|
||||
@@ -556,14 +584,15 @@ abstract class Field
|
||||
$this->SetValid(true);
|
||||
$this->EmptyErrorMessages();
|
||||
|
||||
$bEmpty = ( ($this->GetCurrentValue() === null) || ($this->GetCurrentValue() === '') );
|
||||
if ($this->bValidationDisabled) {
|
||||
return $this->GetValid();
|
||||
}
|
||||
|
||||
if (!$bEmpty || $this->GetMandatory())
|
||||
{
|
||||
foreach ($this->GetValidators() as $oValidator)
|
||||
{
|
||||
if (!preg_match($oValidator->GetRegExp(true), $this->GetCurrentValue()))
|
||||
{
|
||||
$bEmpty = (($this->GetCurrentValue() === null) || ($this->GetCurrentValue() === ''));
|
||||
|
||||
if (!$bEmpty || $this->GetMandatory()) {
|
||||
foreach ($this->GetValidators() as $oValidator) {
|
||||
if (!preg_match($oValidator->GetRegExp(true), $this->GetCurrentValue())) {
|
||||
$this->SetValid(false);
|
||||
$this->AddErrorMessage($oValidator->GetErrorMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user