How to Create Password Field in Magento 2

magento2uicomponent

So i create an xml for form like this

<field name="password">
        <argument name="data" xsi:type="array">
            <item name="config" xsi:type="array">
                <item name="label" xsi:type="string" translate="true">Password</item>
                <item name="dataType" xsi:type="string">password</item>
                <item name="formElement" xsi:type="string">input</item>
                <item name="validation" xsi:type="array">
                    <item name="required-entry" xsi:type="boolean">true</item>
                </item>
            </item>
        </argument>
    </field>

so i want to the field to be like the usual html password field.

i've tried to change the data type to password and nothing happen.

what should i do to accomplish this?

thanks

Best Answer

Try following way:

<field name="password">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
            <item name="elementTmpl" xsi:type="string">Vendor_Module/form/element/password</item>
            <item name="label" xsi:type="string">Password</item>
            <item name="visible" xsi:type="boolean">true</item>
            <item name="dataType" xsi:type="string">text</item>
            <item name="formElement" xsi:type="string">input</item>
        </item>
    </argument>
</field>

Create password.html [Vendor/Module/view/adminhtml/web/template/form/element/password.html]

<input class="input-text" type="password" data-bind="
    hasFocus: focused,
    value: value,
    attr: {
        name: inputName,
        placeholder: placeholder,
        'aria-describedby': noticeId,
        id: uid,
        disabled: disabled
    }"/>
Related Topic