Skip to content

Input Value Copy To

Use this extension when you need to programmatically copy the value from one input element to another input element.

Installation

Add import {InputValueCopyTo} from 'extensions/input-value-copy-to'; to the JavaScript file where this extension will be imported.

Example Usage

.mvt

Apply the data-copy-value-to attribute to the source input element and set the attribute value to the selector of the target input element where the value will be copied over to.

<!-- The source input element -->
<input data-copy-value-to="[name='Customer_VerifyPassword']" id="l-Customer_Password" name="Customer_Password">

<!-- The target input element -->
<input name="Customer_VerifyPassword" id="l-Customer_VerifyPassword" type="hidden">

In the example above, the source input element's value will be copied over to the target input element's value whenever the source input element's value changes or it's field is blurred.

.js

Initialize the InputValueCopyTo object after following the installation step.

import {InputValueCopyTo} from 'extensions/input-value-copy-to';

new InputValueCopyTo();

Override Source Attribute

The copy input value functionality is driven by the default attribute name of data-copy-value-to on the source input element. This attribute name can be overridden by providing an alternative attribute name as the first argument when creating a InputValueCopyTo object.

For example:

new InputValueCopyTo('data-alt-copy-value-to');