Skip to content

Latest commit

 

History

History
172 lines (125 loc) · 8.11 KB

Password.md

File metadata and controls

172 lines (125 loc) · 8.11 KB

Password

The input element with a type attribute whose value is password represents a one-line plain-text edit control for entering a password.

Basic Usage

Instantiate the Password class using Password::widget().

$password = Password::widget();

Generate field id and name

The generateField method is used to generate the field id and name for the HTML output.

Allowed arguments are:

  • modelName - The name of the model.
  • fieldName - The name of the field.
  • arrayable - Whether the field is an array. For default, it is false.
// generate field id and name
$password->generateField('model', 'field');

Setting Attributes

Use the provided methods to set specific attributes for the a element.

// setting class attribute
$password->class('container');

Or, use the attributes method to set multiple attributes at once.

$password->attributes(['class' => 'container', 'style' => 'background-color: #eee;']);

Adding value

If you want to include value in the password element, use the value method.

$password->value('MyValue');

Rendering

Generate the HTML output using the render method, for simple instantiation.

$html = $password->render();

Or, use the magic __toString method.

$html = (string) $password;

Common use cases

Below are examples of common use cases:

// adding multiple attributes
$password->class('external')->value('Myvalue');

// using data attributes
$password->dataAttributes(['analytics' => 'trackClick']);

Explore additional methods for setting various attributes such as lang, name, style, size, title, etc.

Prefix and Suffix

Use prefix and suffix methods to add text before and after the password tag, respectively.

// adding a prefix
$html = $password->value('MyValue')->prefix('MyPrefix')->render();

// adding a suffix
$html = $password->value('MyValue')->suffix('MySuffix')->render();

Template

The template method allows you to customize the HTML output of the a element.

The following template tags are available:

Tag Description
{prefix} The prefix text.
{tag} The a element.
{suffix} The suffix text.
// using a custom template
$password->template('<div>{tag}</div>');

Attributes

Refer to the Attribute Tests for comprehensive examples.

The following methods are available for setting attributes:

Method Description
ariaDescribedBy() Set the aria-describedby attribute.
ariaLabel() Set the aria-label attribute.
attributes() Set multiple attributes at once.
autofocus() Set the autofocus attribute.
class() Set the class attribute.
dataAttributes() Set multiple data-attributes at once.
disabled() Set the disabled attribute.
form() Set the form attribute.
hidden() Set the hidden attribute.
id() Set the id attribute.
lang() Set the lang attribute.
name() Set the name attribute.
placeholder() Set the placeholder attribute.
readOnly() Set the readonly attribute.
size() Set the size attribute.
style() Set the style attribute.
tabIndex() Set the tabindex attribute.
title() Set the title attribute.
value() Set the value attribute.

Custom methods

Refer to the Custom Methods Tests for comprehensive examples.

The following methods are available for customizing the HTML output:

Method Description
generateField() Generate the field id and name for the HTML output.
prefix() Add text before the textarea element.
prefixContainer() Set enabled or disabled for the prefix-container element.
prefixContainerAttributes() Set attributes for the prefix-container element.
prefixContainerClass() Set the class attribute for the prefix-container element.
prefixContainerTag() Set the tag for the prefix-container element.
render() Generates the HTML output.
suffix() Add text after the label element.
suffixContainer() Set enabled or disabled for the suffix-container element.
suffixContainerAttributes() Set attributes for the suffix-container element.
suffixContainerClass() Set the class attribute for the suffix-container element.
suffixContainerTag() Set the tag for the suffix-container element.
template() Set the template for the HTML output.
widget() Instantiates the Password::class.

Validate methods

Refer to the Validate Tests for comprehensive examples.

Method Description
maxLength() Set the maxlength attribute.
minLength() Set the minlength attribute.
pattern() Set the pattern attribute.
required() Set the required attribute.