Magento2 checkout form: How to display placeholder attribute value in fields?

不羁的心 提交于 2019-12-04 05:56:31
Amit Bera

Standard way,

Copy all html files from vendor/magento/module-ui/view/frontend/web/templates/form/element/ at app/design/frontend/<Vendor>/<theme>/Magento_Ui/web/templates/form/element/

Then change all Change placeholder: placeholder to placeholder: label as mention by Akis Verillis.

Now you need to deploy the static files by below code:

 php bin/magento setup:static-content:deploy

And see the magic.

Note: If you have checkout from github then try copy from

/app/code/Magento/Ui/view/base/web/templates/form/element/
Akis Verillis

Change placeholder: placeholder to placeholder: label

The answer is in Magneto 2 documentation now: http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_edit_form.html The templates are the ones mentioned in previous answers. The templates from magento-ui module are used in other places than checkout.

In your custom module directory, create a new /view/frontend/layout/checkout_index_index.xml file. In this file, add content similar to the following:

...
<referenceBlock name="checkout.root">
<arguments>
    <argument name="jsLayout" xsi:type="array">
        ...
        <item name="shippingAddress" xsi:type="array">
            <item name="children" xsi:type="array">
                <!-- The name of the form the field belongs to -->
                <item name="shipping-address-fieldset" xsi:type="array">
                    <item name="children" xsi:type="array">
                        <!-- the field you are customizing -->
                        <item name="telephone" xsi:type="array">
                            <item name="config" xsi:type="array">
                                <!-- Assigning a new template -->
                                <item name="elementTmpl" xsi:type="string">%Vendor_Module%/form/element/%your_template%</item>

%Vendor_Module%/form/element/%your_template% path is [your theme dir]/Vendor_Module/web/template/form/element/your_template.html

Clear browser cache too beside: Delete all files in the pub/static/frontend and var/view_preprocessing directories.

hiperboreo

If this is useful for you, the definition of that element is in: /app/code/Magento/Ui/view/base/web/templates/form/element/input.html It defines an input as:

<input
class="admin__control-text"
type="text"
data-bind="
    value: value,
    hasFocus: focused,
    attr: {
        name: inputName,
        placeholder: placeholder,
        'aria-describedby': noticeId,
        id: uid,
        disabled: disabled
}" />
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!