mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-20 03:16:12 +00:00
mvc, model. Validation issue when storing a value for the first time.
If a field isn't required and the user sets it with a faulty value, it would pass because it didn't know it wasn't set before user input. There where two issues, first one, not knowing it was in init state (solved with internalFieldLoaded), next all field types should have used actionPostLoadingEvent to customize loading behaviour.
This commit is contained in:
parent
f039e9211d
commit
091b075476
@ -71,7 +71,7 @@ class AuthGroupField extends BaseField
|
||||
/**
|
||||
* generate validation data (list of certificates)
|
||||
*/
|
||||
public function eventPostLoading()
|
||||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (empty(self::$internalOptionList)) {
|
||||
$cnf = Config::getInstance()->object();
|
||||
|
||||
@ -74,7 +74,7 @@ class AuthenticationServerField extends BaseField
|
||||
/**
|
||||
* generate validation data (list of AuthServers)
|
||||
*/
|
||||
public function eventPostLoading()
|
||||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (!isset(self::$internalOptionList[$this->internalCacheKey])) {
|
||||
self::$internalOptionList[$this->internalCacheKey] = array();
|
||||
|
||||
@ -112,6 +112,11 @@ abstract class BaseField
|
||||
*/
|
||||
private $internalChangeCase = null;
|
||||
|
||||
/**
|
||||
* @var bool is field loaded (after post loading event)
|
||||
*/
|
||||
private $internalFieldLoaded = false;
|
||||
|
||||
/**
|
||||
* generate a new UUID v4 number
|
||||
* @return string uuid v4 number
|
||||
@ -150,6 +155,7 @@ abstract class BaseField
|
||||
$node->eventPostLoading();
|
||||
}
|
||||
$this->actionPostLoadingEvent();
|
||||
$this->internalFieldLoaded = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -287,8 +293,8 @@ abstract class BaseField
|
||||
*/
|
||||
public function setValue($value)
|
||||
{
|
||||
// if first set, store initial value
|
||||
if ($this->internalInitialValue === false && $value != "") {
|
||||
// if first set and not altered by the user, store initial value
|
||||
if ($this->internalFieldLoaded === false && $this->internalInitialValue === false && $value != "") {
|
||||
$this->internalInitialValue = $value;
|
||||
}
|
||||
$this->internalValue = $value;
|
||||
|
||||
@ -96,7 +96,7 @@ class CertificateField extends BaseField
|
||||
/**
|
||||
* generate validation data (list of certificates)
|
||||
*/
|
||||
public function eventPostLoading()
|
||||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (!isset(self::$internalOptionList[$this->certificateType])) {
|
||||
self::$internalOptionList[$this->certificateType] = array();
|
||||
|
||||
@ -66,7 +66,7 @@ class ConfigdActionsField extends BaseField
|
||||
/**
|
||||
* generate validation data (list of known configd actions)
|
||||
*/
|
||||
public function eventPostLoading()
|
||||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (!isset(self::$internalOptionList[$this->internalCacheKey])) {
|
||||
self::$internalOptionList[$this->internalCacheKey] = array();
|
||||
|
||||
@ -66,7 +66,7 @@ class CountryField extends BaseField
|
||||
/**
|
||||
* generate validation data (list of countries)
|
||||
*/
|
||||
public function eventPostLoading()
|
||||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (count(self::$internalOptionList) == 0) {
|
||||
$filename = '/usr/local/opnsense/contrib/tzdata/iso3166.tab';
|
||||
|
||||
@ -120,7 +120,7 @@ class InterfaceField extends BaseField
|
||||
/**
|
||||
* generate validation data (list of interfaces and well know ports)
|
||||
*/
|
||||
public function eventPostLoading()
|
||||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (!isset(self::$internalOptionList[$this->internalCacheKey])) {
|
||||
self::$internalOptionList[$this->internalCacheKey] = array();
|
||||
|
||||
@ -101,7 +101,7 @@ class PortField extends BaseField
|
||||
/**
|
||||
* generate validation data (list of port numbers and well know ports)
|
||||
*/
|
||||
public function eventPostLoading()
|
||||
protected function actionPostLoadingEvent()
|
||||
{
|
||||
if (!is_array(self::$internalOptionList)) {
|
||||
self::$internalOptionList = array("any") + self::$wellknownservices;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user