1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-11 09:14:58 +02:00

Update InputfieldPassword to support configurable placeholder attributes for old/new/confirm inputs via oldPassLabel, newPassLabel, confirmLabel properties that can be set from hooks.

This commit is contained in:
Ryan Cramer
2020-01-05 07:31:11 -05:00
parent 51629cdd5f
commit 321ea0eed3

View File

@@ -3,7 +3,7 @@
/** /**
* An Inputfield for handling a password * An Inputfield for handling a password
* *
* ProcessWire 3.x, Copyright 2019 by Ryan Cramer * ProcessWire 3.x, Copyright 2020 by Ryan Cramer
* https://processwire.com * https://processwire.com
* *
* @property array $requirements Array of requirements (See require* constants) * @property array $requirements Array of requirements (See require* constants)
@@ -13,6 +13,9 @@
* @property int $requireOld Require previous password? 0=Auto, 1=Yes, -1=No, Default=0 (Auto) * @property int $requireOld Require previous password? 0=Auto, 1=Yes, -1=No, Default=0 (Auto)
* @property bool $showPass Allow password to be rendered in renderValue and/or re-populated in form? * @property bool $showPass Allow password to be rendered in renderValue and/or re-populated in form?
* @property string $defaultLabel Default label for field (default='Set Password'). Used when no 'label' has been set. * @property string $defaultLabel Default label for field (default='Set Password'). Used when no 'label' has been set.
* @property string $oldPassLabel Label for old/current password placeholder.
* @property string $newPassLabel Label for new password placeholder.
* @property string $confirmLabel Label for password confirm placeholder.
* *
*/ */
class InputfieldPassword extends InputfieldText { class InputfieldPassword extends InputfieldText {
@@ -111,6 +114,9 @@ class InputfieldPassword extends InputfieldText {
self::requireNone => $this->_('none (disable all above)'), self::requireNone => $this->_('none (disable all above)'),
)); ));
$this->set('showPass', false); // allow password to be rendered in renderValue and/or re-populated in form? $this->set('showPass', false); // allow password to be rendered in renderValue and/or re-populated in form?
$this->set('oldPassLabel', $this->_('Current password'));
$this->set('newPassLabel', $this->_('New password'));
$this->set('confirmLabel', $this->_('Confirm'));
} }
/** /**
@@ -164,7 +170,9 @@ class InputfieldPassword extends InputfieldText {
* *
*/ */
public function ___render() { public function ___render() {
/** @var Sanitizer $sanitizer */
$sanitizer = $this->wire('sanitizer');
$minlength = (int) $this->attr('minlength'); $minlength = (int) $this->attr('minlength');
$requirements = array(); $requirements = array();
@@ -209,9 +217,9 @@ class InputfieldPassword extends InputfieldText {
$failIcon = "<i class='fa fa-fw fa-frown-o'></i>"; $failIcon = "<i class='fa fa-fw fa-frown-o'></i>";
$okIcon = "<i class='fa fa-fw fa-meh-o'></i>"; $okIcon = "<i class='fa fa-fw fa-meh-o'></i>";
$goodIcon = "<i class='fa fa-fw fa-smile-o'></i>"; $goodIcon = "<i class='fa fa-fw fa-smile-o'></i>";
$oldPassLabel = $this->_('Current password'); $oldPassLabel = $sanitizer->entities1($this->oldPassLabel);
$newPassLabel = $this->_('New password'); $newPassLabel = $sanitizer->entities1($this->newPassLabel);
$confirmLabel = $this->_('Confirm'); $confirmLabel = $sanitizer->entities1($this->confirmLabel);
$name = $this->attr('name'); $name = $this->attr('name');
$id = $this->attr('id'); $id = $this->attr('id');
$size = $this->attr('size'); $size = $this->attr('size');