*}{if $field->getDocument()->isAjax()} data-dialog-submit-on-enter="true"{/if}{*
*}{foreach from=$field->getFieldAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}{*
*}>
+
+{if $field->getStrengthMeter()}
+ <script data-relocate="true">
+ require(["WoltLabSuite/Core/Ui/User/PasswordStrength", "Language"], (PasswordStrength, Language) => {
+ {include file='shared_passwordStrengthLanguage'}
+
+ new PasswordStrength(document.getElementById('{unsafe:$field->getPrefixedId()|encodeJS}'), {
+ relatedInputs: [
+ {foreach from=$field->getRelatedFieldsIDs() item=fieldId}
+ document.getElementById('{unsafe:$fieldId|encodeJS}'),
+ {/foreach}
+ ],
+ });
+ });
+ </script>
+{/if}
->removeFieldClass('medium')
->addFieldClass('long')
->autocomplete('current-password')
+ ->addMeterRelatedFieldId('username')
->addValidator(new FormFieldValidator(
'passwordValidator',
$this->validatePassword(...)
->required()
->removeFieldClass('medium')
->addFieldClass('long')
+ ->addMeterRelatedFieldId('username')
+ ->addMeterRelatedFieldId('email')
->autocomplete('current-password')
->addValidator(new FormFieldValidator(
'passwordValidator',
*/
protected $templateName = 'shared_passwordFormField';
+ protected bool $strengthMeter = true;
+ /**
+ * @var IFormField[]
+ */
+ protected array $relatedFields = [];
+ /**
+ * @var string[]
+ */
+ protected array $relatedFieldsId = [];
+
/**
* Creates a new instance of `PasswordFormField`.
*/
parent::validate();
}
+ /**
+ * Sets if the password strength meter should be used to provide feedback
+ * to the user about the strength of their password.
+ */
+ public function passwordStrengthMeter(bool $passwordStrengthMeter = true): self
+ {
+ $this->strengthMeter = $passwordStrengthMeter;
+
+ return $this;
+ }
+
/**
* @inheritDoc
*/
{
return ['new-password', 'current-password'];
}
+
+ public function addMeterRelatedField(IFormField $input): self
+ {
+ $this->relatedFields[] = $input;
+
+ return $this;
+ }
+
+ public function addMeterRelatedFieldId(string $fieldId): self
+ {
+ $this->relatedFieldsId[] = $fieldId;
+
+ return $this;
+ }
+
+ public function getStrengthMeter(): bool
+ {
+ return $this->strengthMeter;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getRelatedFieldsIDs(): array
+ {
+ $result = $this->relatedFieldsId;
+ foreach ($this->relatedFields as $field) {
+ $result[] = $field->getPrefixedId();
+ }
+
+ return $result;
+ }
}