mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 15:57:01 +02:00
Add support for HTML5 autocomplete attributes to InputfieldText, when used of page editing forms
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* An Inputfield for handling single line "text" form inputs
|
* An Inputfield for handling single line "text" form inputs
|
||||||
*
|
*
|
||||||
* ProcessWire 3.x, Copyright 2023 by Ryan Cramer
|
* ProcessWire 3.x, Copyright 2025 by Ryan Cramer
|
||||||
* https://processwire.com
|
* https://processwire.com
|
||||||
*
|
*
|
||||||
* @property string $type Input type (typically "text")
|
* @property string $type Input type (typically "text")
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
* @property int $minlength Minimum allowed length of value (usually combined with 'required' option)
|
* @property int $minlength Minimum allowed length of value (usually combined with 'required' option)
|
||||||
* @property int $maxlength Maximum allowed length of value
|
* @property int $maxlength Maximum allowed length of value
|
||||||
* @property string $placeholder Placeholder attribute text
|
* @property string $placeholder Placeholder attribute text
|
||||||
|
* @property string|null $autocomplete HTML5 autocomplete attribute, used only by text and email, not other descending types (3.0.252+)
|
||||||
* @property string $pattern HTML5 pattern attribute
|
* @property string $pattern HTML5 pattern attribute
|
||||||
* @property string $initValue Optional initial/default value
|
* @property string $initValue Optional initial/default value
|
||||||
* @property bool $stripTags Should HTML tags be stripped from value?
|
* @property bool $stripTags Should HTML tags be stripped from value?
|
||||||
@@ -170,6 +171,20 @@ class InputfieldText extends Inputfield {
|
|||||||
if(strlen($placeholder)) $attrs['placeholder'] = $placeholder;
|
if(strlen($placeholder)) $attrs['placeholder'] = $placeholder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$autocomplete = strtolower((string) $this->getSetting('autocomplete'));
|
||||||
|
if($autocomplete && !isset($attrs['autocomplete'])) {
|
||||||
|
$type = strtolower(str_replace('Inputfield', '', $this->className()));
|
||||||
|
if($type === 'text' || $this->type === 'email' || $this->type === 'tel') {
|
||||||
|
if($type === 'text') {
|
||||||
|
$attrs['autocomplete'] = $autocomplete;
|
||||||
|
} else if($autocomplete === 'on' || $autocomplete === 'off') {
|
||||||
|
$attrs['autocomplete'] = $autocomplete;
|
||||||
|
} else if($this->type === $autocomplete) {
|
||||||
|
$attrs['autocomplete'] = $autocomplete; // email or tel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $attrs;
|
return $attrs;
|
||||||
}
|
}
|
||||||
@@ -384,7 +399,32 @@ class InputfieldText extends Inputfield {
|
|||||||
$field->collapsed = Inputfield::collapsedBlank;
|
$field->collapsed = Inputfield::collapsedBlank;
|
||||||
$inputfields->append($field);
|
$inputfields->append($field);
|
||||||
|
|
||||||
if($this->hasFieldtype === false) {
|
if($this->hasFieldtype === false) {
|
||||||
|
$type = strtolower(str_replace('Inputfield', '', $this->className()));
|
||||||
|
if($this->type === 'email') $type = 'email';
|
||||||
|
if($type === 'text' || $type === 'email' || $this->type === 'tel') {
|
||||||
|
$f = $inputfields->InputfieldSelect;
|
||||||
|
$f->attr('name', 'autocomplete');
|
||||||
|
$f->label = $this->_('Autocomplete');
|
||||||
|
$f->valueAddOption = true;
|
||||||
|
$f->collapsed = Inputfield::collapsedBlank;
|
||||||
|
$f->addOption('', $this->_('None'));
|
||||||
|
$f->addOption('on', $this->_('On'));
|
||||||
|
$f->addOption('off', $this->_('Off'));
|
||||||
|
if($type === 'text' || $type === 'email') $f->addOption('email', $this->_('Email'));
|
||||||
|
if($type === 'text' || $this->type === 'tel') $f->addOption('tel', $this->_('Tel (phone number)'));
|
||||||
|
if($this->type === 'text') {
|
||||||
|
$f->addOption('given-name', $this->_('Given-name (first name)'));
|
||||||
|
$f->addOption('family-name', $this->_('Family-name (last name)'));
|
||||||
|
$f->addOption('name', $this->_('Name (full name)'));
|
||||||
|
$f->addOption('street-address', $this->_('Street-address'));
|
||||||
|
$f->addOption('username', $this->_('Username'));
|
||||||
|
$f->addOption('one-time-code', $this->_('One-time-code (verification code)'));
|
||||||
|
}
|
||||||
|
$f->val($this->getSetting('autocomplete'));
|
||||||
|
$inputfields->add($f);
|
||||||
|
}
|
||||||
|
|
||||||
/** @var InputfieldText $field */
|
/** @var InputfieldText $field */
|
||||||
$field = $modules->get($this->className());
|
$field = $modules->get($this->className());
|
||||||
$field->setAttribute('name', 'initValue');
|
$field->setAttribute('name', 'initValue');
|
||||||
|
Reference in New Issue
Block a user