PHP Class yii\widgets\MaskedInput

MaskedInput is similar to [[Html::textInput()]] except that an input mask will be used to force users to enter properly formatted data, such as phone numbers, social security numbers. To use MaskedInput, you must set the [[mask]] property. The following example shows how to use MaskedInput to collect phone numbers: ~~~ echo MaskedInput::widget([ 'name' => 'phone', 'mask' => '999-999-9999', ]); ~~~ The masked text field is implemented based on the jQuery masked input plugin.
Since: 2.0
Author: Qiang Xue ([email protected])
Inheritance: extends InputWidget
Afficher le fichier Open project: yiisoft/yii2 Class Usage Examples

Méthodes publiques

Свойство Type Description
$aliases custom aliases to use. Should be configured as maskAlias => settings, where - maskAlias is a string containing a text to identify your mask alias definition (e.g. 'phone') and - settings is an array containing settings for the mask symbol, exactly similar to parameters as passed in [[clientOptions]].
$clientOptions the JQuery plugin options for the input mask plugin.
$definitions custom mask definitions to use. Should be configured as maskSymbol => settings, where - maskSymbol is a string, containing a character to identify your mask definition and - settings is an array, consisting of the following entries: - validator: string, a JS regular expression or a JS function. - cardinality: int, specifies how many characters are represented and validated for the definition. - prevalidator: array, validate the characters before the definition cardinality is reached. - definitionSymbol: string, allows shifting values from other definitions, with this definitionSymbol.
$mask the input mask (e.g. '99/99/9999' for date input). The following characters can be used in the mask and are predefined: - a: represents an alpha character (A-Z, a-z) - 9: represents a numeric character (0-9) - *: represents an alphanumeric character (A-Z, a-z, 0-9) - [ and ]: anything entered between the square brackets is considered optional user input. This is based on the optionalmarker setting in [[clientOptions]]. Additional definitions can be set through the [[definitions]] property.
$options the HTML attributes for the input tag.
$type the type of the input tag. Currently only 'text' and 'tel' are supported.

Protected Properties

Свойство Type Description
$_hashVar the hashed variable to store the pluginOptions

Méthodes publiques

Méthode Description
init ( ) Initializes the widget.
registerClientScript ( ) Registers the needed client script and options.
run ( )

Méthodes protégées

Méthode Description
hashPluginOptions ( View $view ) Generates a hashed variable to store the plugin clientOptions. Helps in reusing the variable for similar options passed for other widgets on the same page. The following special data attribute will also be added to the input field to allow accessing the client options via javascript:
initClientOptions ( ) Initializes client options

Method Details

hashPluginOptions() protected méthode

- 'data-plugin-inputmask' will store the hashed variable storing the plugin options.
Author: [Thiago Talma](https://github.com/thiagotalma)
protected hashPluginOptions ( View $view )
$view yii\web\View the view instance

init() public méthode

Initializes the widget.
public init ( )

initClientOptions() protected méthode

Initializes client options
protected initClientOptions ( )

registerClientScript() public méthode

Registers the needed client script and options.

run() public méthode

public run ( )

Property Details

$_hashVar protected_oe property

the hashed variable to store the pluginOptions
protected $_hashVar

$aliases public_oe property

custom aliases to use. Should be configured as maskAlias => settings, where - maskAlias is a string containing a text to identify your mask alias definition (e.g. 'phone') and - settings is an array containing settings for the mask symbol, exactly similar to parameters as passed in [[clientOptions]].
public $aliases

$clientOptions public_oe property

the JQuery plugin options for the input mask plugin.
See also: https://github.com/RobinHerbots/jquery.inputmask
public $clientOptions

$definitions public_oe property

custom mask definitions to use. Should be configured as maskSymbol => settings, where - maskSymbol is a string, containing a character to identify your mask definition and - settings is an array, consisting of the following entries: - validator: string, a JS regular expression or a JS function. - cardinality: int, specifies how many characters are represented and validated for the definition. - prevalidator: array, validate the characters before the definition cardinality is reached. - definitionSymbol: string, allows shifting values from other definitions, with this definitionSymbol.
public $definitions

$mask public_oe property

the input mask (e.g. '99/99/9999' for date input). The following characters can be used in the mask and are predefined: - a: represents an alpha character (A-Z, a-z) - 9: represents a numeric character (0-9) - *: represents an alphanumeric character (A-Z, a-z, 0-9) - [ and ]: anything entered between the square brackets is considered optional user input. This is based on the optionalmarker setting in [[clientOptions]]. Additional definitions can be set through the [[definitions]] property.
public $mask

$options public_oe property

the HTML attributes for the input tag.
See also: yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
public $options

$type public_oe property

the type of the input tag. Currently only 'text' and 'tel' are supported.
See also: https://github.com/RobinHerbots/jquery.inputmask
Since: 2.0.6
public $type