Form text/password/number fields now support maxlength attribute - Fixes #1210
This commit is contained in:
parent
c2c14e707f
commit
37e5b2328f
|
|
@ -1,3 +1,6 @@
|
|||
* **Build 27x** (2015-06-xx)
|
||||
- Protected images and their thumbnails are now supported in the back-end.
|
||||
|
||||
* **Build 271** (2015-06-20)
|
||||
- File Upload form widget can now specify `mimeTypes` to define MIME types that are accepted by the uploader, either as file extension or fully qualified name.
|
||||
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ class FormField
|
|||
* - field: Attributes are added to the form field element (input, select, textarea, etc)
|
||||
* - container: Attributes are added to the form field container (div.form-group)
|
||||
* @param array $items
|
||||
* @param strubg $position
|
||||
* @param string $position
|
||||
* @return void
|
||||
*/
|
||||
public function attributes($items, $position = 'field')
|
||||
|
|
@ -359,6 +359,23 @@ class FormField
|
|||
foreach ($items as $_position => $_items) {
|
||||
$this->attributes($_items, $_position);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the field has the supplied [unfiltered] attribute.
|
||||
* @param string $name
|
||||
* @param string $position
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAttribute($name, $position = 'field')
|
||||
{
|
||||
if (!isset($this->attributes[$position])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return array_key_exists($name, $this->attributes[$position]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -402,20 +419,23 @@ class FormField
|
|||
*/
|
||||
protected function filterTriggerAttributes($attributes, $position = 'field')
|
||||
{
|
||||
if (!$this->trigger || !is_array($this->trigger))
|
||||
if (!$this->trigger || !is_array($this->trigger)) {
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
$triggerAction = array_get($this->trigger, 'action');
|
||||
$triggerField = array_get($this->trigger, 'field');
|
||||
$triggerCondition = array_get($this->trigger, 'condition');
|
||||
|
||||
// Apply these to container
|
||||
if (in_array($triggerAction, ['hide', 'show']) && $position != 'container')
|
||||
if (in_array($triggerAction, ['hide', 'show']) && $position != 'container') {
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
// Apply these to field/input
|
||||
if (in_array($triggerAction, ['enable', 'disable', 'empty']) && $position != 'field')
|
||||
if (in_array($triggerAction, ['enable', 'disable', 'empty']) && $position != 'field') {
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
if ($this->arrayName) {
|
||||
$fullTriggerField = $this->arrayName.'['.implode('][', HtmlHelper::nameToArray($triggerField)).']';
|
||||
|
|
@ -443,8 +463,9 @@ class FormField
|
|||
*/
|
||||
protected function filterPresetAttributes($attributes, $position = 'field')
|
||||
{
|
||||
if (!$this->preset || $position != 'field')
|
||||
if (!$this->preset || $position != 'field') {
|
||||
return $attributes;
|
||||
}
|
||||
|
||||
if (!is_array($this->preset)) {
|
||||
$this->preset = ['field' => $this->preset, 'type' => 'slug'];
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@
|
|||
placeholder="<?= e(trans($field->placeholder)) ?>"
|
||||
class="form-control"
|
||||
autocomplete="off"
|
||||
maxlength="255"
|
||||
pattern="-?\d+(\.\d+)?"
|
||||
<?= $field->hasAttribute('maxlength') ? '' : 'maxlength="255"' ?>
|
||||
<?= $field->getAttributes() ?>
|
||||
/>
|
||||
<?php endif ?>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
value=""
|
||||
class="form-control"
|
||||
autocomplete="off"
|
||||
maxlength="255"
|
||||
<?= $field->hasAttribute('maxlength') ? '' : 'maxlength="255"' ?>
|
||||
<?= $field->getAttributes() ?>
|
||||
/>
|
||||
<?php endif ?>
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
placeholder="<?= e(trans($field->placeholder)) ?>"
|
||||
class="form-control"
|
||||
autocomplete="off"
|
||||
maxlength="255"
|
||||
<?= $field->hasAttribute('maxlength') ? '' : 'maxlength="255"' ?>
|
||||
<?= $field->getAttributes() ?>
|
||||
/>
|
||||
<?php endif ?>
|
||||
Loading…
Reference in New Issue