mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-12 23:14:18 +01: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());
|
||||
}
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
|
||||
namespace Combodo\iTop\Form;
|
||||
|
||||
use \Exception;
|
||||
use \Dict;
|
||||
use \Combodo\iTop\Form\Field\Field;
|
||||
use \Combodo\iTop\Form\Field\CaseLogField;
|
||||
use \Combodo\iTop\Form\Field\SubFormField;
|
||||
use Combodo\iTop\Form\Field\CaseLogField;
|
||||
use Combodo\iTop\Form\Field\Field;
|
||||
use Combodo\iTop\Form\Field\SubFormField;
|
||||
use Dict;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Description of Form
|
||||
@@ -34,6 +34,7 @@ class Form
|
||||
{
|
||||
protected $sId;
|
||||
protected $sTransactionId;
|
||||
/** @var \Combodo\iTop\Form\Field\Field[] */
|
||||
protected $aFields;
|
||||
protected $aDependencies;
|
||||
protected $bValid;
|
||||
@@ -566,17 +567,14 @@ class Form
|
||||
$this->SetValid(true);
|
||||
$this->EmptyErrorMessages();
|
||||
|
||||
foreach ($this->aFields as $oField)
|
||||
{
|
||||
if (!$oField->Validate())
|
||||
{
|
||||
$this->SetValid(false);
|
||||
foreach ($oField->GetErrorMessages() as $sErrorMessage)
|
||||
{
|
||||
$this->AddErrorMessage(Dict::S($sErrorMessage), $oField->Getid());
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($this->aFields as $oField) {
|
||||
if (!$oField->Validate()) {
|
||||
$this->SetValid(false);
|
||||
foreach ($oField->GetErrorMessages() as $sErrorMessage) {
|
||||
$this->AddErrorMessage(Dict::S($sErrorMessage), $oField->Getid());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->GetValid();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user