Upgrade to 3.2.5
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
namespace Kirby\Form;
|
||||
|
||||
use Exception;
|
||||
use Kirby\Cms\App;
|
||||
use Kirby\Cms\Model;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Toolkit\Component;
|
||||
@@ -23,7 +22,6 @@ use Kirby\Toolkit\V;
|
||||
*/
|
||||
class Field extends Component
|
||||
{
|
||||
|
||||
/**
|
||||
* Registry for all component mixins
|
||||
*
|
||||
@@ -51,6 +49,10 @@ class Field extends Component
|
||||
throw new InvalidArgumentException('The field type "' . $type . '" does not exist');
|
||||
}
|
||||
|
||||
if (isset($attrs['model']) === false) {
|
||||
throw new InvalidArgumentException('Field requires a model');
|
||||
}
|
||||
|
||||
// use the type as fallback for the name
|
||||
$attrs['name'] = $attrs['name'] ?? $type;
|
||||
$attrs['type'] = $type;
|
||||
@@ -71,6 +73,7 @@ class Field extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
*/
|
||||
public function data($default = false)
|
||||
@@ -177,6 +180,39 @@ class Field extends Component
|
||||
'value' => function ($value = null) {
|
||||
return $value;
|
||||
}
|
||||
],
|
||||
'computed' => [
|
||||
'after' => function () {
|
||||
if ($this->after !== null) {
|
||||
return $this->model()->toString($this->after);
|
||||
}
|
||||
},
|
||||
'before' => function () {
|
||||
if ($this->before !== null) {
|
||||
return $this->model()->toString($this->before);
|
||||
}
|
||||
},
|
||||
'default' => function () {
|
||||
if ($this->default === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_string($this->default) === false) {
|
||||
return $this->default;
|
||||
}
|
||||
|
||||
return $this->model()->toString($this->default);
|
||||
},
|
||||
'label' => function () {
|
||||
if ($this->label !== null) {
|
||||
return $this->model()->toString($this->label);
|
||||
}
|
||||
},
|
||||
'placeholder' => function () {
|
||||
if ($this->placeholder !== null) {
|
||||
return $this->model()->toString($this->placeholder);
|
||||
}
|
||||
}
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -217,7 +253,7 @@ class Field extends Component
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Kirby\Cms\App
|
||||
* @return \Kirby\Cms\App
|
||||
*/
|
||||
public function kirby()
|
||||
{
|
||||
|
@@ -16,14 +16,13 @@ use Kirby\Toolkit\Collection;
|
||||
*/
|
||||
class Fields extends Collection
|
||||
{
|
||||
|
||||
/**
|
||||
* Internal setter for each object in the Collection.
|
||||
* This takes care of validation and of setting
|
||||
* the collection prop on each object correctly.
|
||||
*
|
||||
* @param string $id
|
||||
* @param object $object
|
||||
* @param string $name
|
||||
* @param object $field
|
||||
*/
|
||||
public function __set(string $name, $field)
|
||||
{
|
||||
|
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace Kirby\Form;
|
||||
|
||||
use Throwable;
|
||||
use Kirby\Data\Yaml;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* The main form class, that is being
|
||||
@@ -37,7 +37,7 @@ class Form
|
||||
|
||||
unset($inject['fields'], $inject['values'], $inject['input']);
|
||||
|
||||
$this->fields = new Fields;
|
||||
$this->fields = new Fields();
|
||||
$this->values = [];
|
||||
|
||||
foreach ($fields as $name => $props) {
|
||||
|
@@ -4,8 +4,8 @@ namespace Kirby\Form;
|
||||
|
||||
use Kirby\Cms\Nest;
|
||||
use Kirby\Exception\InvalidArgumentException;
|
||||
use Kirby\Toolkit\Query;
|
||||
use Kirby\Toolkit\Properties;
|
||||
use Kirby\Toolkit\Query;
|
||||
use Kirby\Toolkit\Str;
|
||||
|
||||
/**
|
||||
|
@@ -107,6 +107,19 @@ class Validations
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function pattern(Field $field, $value): bool
|
||||
{
|
||||
if ($field->isEmpty($value) === false && $field->pattern() !== null) {
|
||||
if (V::match($value, '/' . $field->pattern() . '/i') === false) {
|
||||
throw new InvalidArgumentException(
|
||||
V::message('match')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function required(Field $field, $value): bool
|
||||
{
|
||||
if ($field->isRequired() === true && $field->save() === true && $field->isEmpty($value) === true) {
|
||||
|
Reference in New Issue
Block a user