7

早安 Stackoverflow,

我正在自定义 Magento 2 中的结帐单页。现在我正在尝试在送货地址表单中显示占位符而不是标签,但到目前为止还没有成功。我希望有人可以帮助我

干杯,豪尔赫

更新:

在控制台中,我可以看到一个变量赋予元素输入的属性占位符。

<input class="input-text" type="text" data-bind="
    value: value,
    valueUpdate: 'keyup',
    hasFocus: focused,
    attr: {
        name: inputName,
        placeholder: placeholder, // <<<< right here
        'aria-describedby': noticeId,
        id: uid,
        disabled: disabled
    }" name="street[0]" placeholder="" aria-describedby="notice-BVWUCFN" id="BVWUCFN">

现在我想知道是否有办法通过后端修改这个变量,所以我可以在占位符 attr 中显示标签名称。 看截图

为我糟糕的英语道歉

4

5 回答 5

8

标准方式,

vendor/magento/module-ui/view/frontend/web/templates/form/element/ 从at 复制所有 html 文件app/design/frontend/<Vendor>/<theme>/Magento_Ui/web/templates/form/element/

然后将所有更改更改placeholder: placeholderAkis Verillisplaceholder: label提到的 。

现在您需要通过以下代码部署静态文件:

 php bin/magento setup:static-content:deploy

并看到魔法。

注意: 如果您从 github 结帐,请尝试从

/app/code/Magento/Ui/view/base/web/templates/form/element/
于 2016-04-05T07:34:17.853 回答
3

更改placeholder: placeholderplaceholder: label

于 2016-02-26T10:04:34.617 回答
2

答案现在在 Magneto 2 文档中: http: //devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_edit_form.html 模板是前面答案中提到的模板。magento-ui 模块中的模板用于结帐以外的其他地方。

在您的自定义模块目录中,创建一个新的 /view/frontend/layout/checkout_index_index.xml 文件。在此文件中,添加类似于以下内容的内容:

...
<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% 路径是 [你的主题目录]/Vendor_Module/web/template/form/element/your_template.html

也清除浏览器缓存:删除 pub/static/frontend 和 var/view_preprocessing 目录中的所有文件。

于 2016-04-30T18:39:18.607 回答
1

如果这对您有用,那么该元素的定义在: /app/code/Magento/Ui/view/base/web/templates/form/element/input.html 它将输入定义为:

<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
}" />
于 2016-03-03T07:05:09.887 回答
1

您可以将placeholder项目添加到您的字段的 layout.xml 文件中。像这样:

<item name="address" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/form/element/abstract</item>
<item name="config" xsi:type="array">
   <item name="customScope" xsi:type="string">contactForm</item>
   <item name="template" xsi:type="string">ui/form/field</item>
   <item name="elementTmpl" xsi:type="string">ui/form/element/input</item>
</item>
<item name="placeholder" xsi:type="string">Address</item>
<item name="dataScope" xsi:type="string">address</item>
<item name="label" xsi:type="string">Address</item>
<item name="sortOrder" xsi:type="string">20</item>
<item name="validation" xsi:type="array">
  <item name="required-entry" xsi:type="string">true</item>
</item>

于 2020-05-21T08:06:53.707 回答