【问题标题】:Not able to save the user selected picklist value in SFCC Demandware无法在 SFCC Demandware 中保存用户选择的选项列表值
【发布时间】:2021-01-07 12:20:32
【问题描述】:

我在标准“配置文件”对象中创建了一个新属性(favouriteStore - 字符串数据类型的枚举),并将其添加到店面的帐户创建页面。现在,我无法将用户选择的选项列表值从 ISML 获取到 js。我尝试了下面的代码,它返回未定义。你能帮我解决这个问题吗?

下面是isml代码:registerForm.isml

 <div class="form-group
        <isif condition=" ${!!pdict.profileForm.customer.favouriteStore.mandatory === true}">required</isif>">

        <label class="form-control-label" for="registration-form-favouriteStore">
            <isprint value="${pdict.profileForm.customer.favouriteStore.label}" encoding="htmlcontent" />
        </label>
        <div class="info-icon">
            <span><i class="fa fa-info-circle beet-color" aria-hidden="true"></i></span>
            <span class="tooltip account-tooltip d-none">Pick your favourite store</span>
        </div>
        <select class="custom-select form-control" id="favouriteStore" onchange="getSelected(this)" name="favouriteStore">
        <isloop items=${pdict.profileForm.customer.favouriteStore.options} var="store">
            <option id="${store.id}" value="${store.htmlValue}" 
            <isif condition="${store.selected}">selected</isif> >${store.label}</option>
        </isloop>
        </select>
    </div>

JS代码:Account.js

var registrationFormObj = {
            firstName: registrationForm.customer.firstname.value,
            lastName: registrationForm.customer.lastname.value,
            phone: registrationForm.customer.phone.value,
            email: registrationForm.customer.email.value,
            emailConfirm: registrationForm.customer.emailconfirm.value,
            password: registrationForm.login.password.value,
            passwordConfirm: registrationForm.login.passwordconfirm.value,
            customerPostcode: registrationForm.customer.customerPostcode.value,
            favouriteStore: registrationForm.customer.favouriteStore.value,
            marketingPreferences: registrationForm.customer.marketingPreferences.value,
            validForm: registrationForm.valid,
            form: registrationForm
        };

profile.xml:

<field formid="favouriteStore" label="Favourite Store" type="string" mandatory="true" binding="favouriteStore">
            <options>
                <option optionid="" label="" value=""/>
                <option optionid="1" label="Shell Kingsburn, Borough of Royal Kensington, London EC2 3AH" value="Shell Kingsburn Borough of Royal Kensington, London EC2 3AH"/>
                <option optionid="2" label="Chealsea, City Road, London EC2 9AW" value="Chealsea, City Road, London EC2 9AW"/>
                <option optionid="3" label="London Store, 2nd Street, London  EC2 9AW" value="London Store, 2nd Street, London  EC2 9AW"/>
            </options>
            </field>

所有其他字符串字段都被保存,只是这个 favouriteStore 选项列表字段返回未定义。请您指导我哪里出了问题。

提前致谢!

【问题讨论】:

  • 你在registrationForm.customer.favoriteStore.value字段中拼错了“最喜欢的”
  • @AlBlue 感谢您的回复!对不起这是我的错。我纠正了它。但是,选项列表字段仍然是空白的。如果代码有任何其他问题,请告诉我

标签: salesforce picklist demandware isml


【解决方案1】:

正如AlBlue 所提到的,问题似乎是您在ISML 和DWScript 中没有以相同的方式拼写favouriteStore。 (JavaScript)

也就是说,您应该确保您还为该字段定义了表单 XML。例如,您应该将其添加到店面墨盒的cartridge/forms/default/profile.xml 文件中。 (或覆盖来自app_storefront_base 的那个)

【讨论】:

  • 感谢您的回复!即使在更新后,我也面临问题..该值未保存在对象级别。我还添加了 xml 代码。能否请您检查一下,如果还有其他问题,请告诉我。
  • @AIBlue 和 sholsinger 问题出在 ISML 中的 onchange="getSelected(this)" 上。删除它并添加 以选择标签后,保存成功!我还有一个问题是,我必须将所有逗号 (,) 替换为 break (
    ) 或字符串中的换行符。我使用了字符串类的替换方法。但是,它没有按预期工作。你能告诉我如何使用它的语法吗?非常感谢您的帮助!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-02
  • 1970-01-01
  • 1970-01-01
  • 2020-04-20
  • 1970-01-01
  • 2022-01-27
相关资源
最近更新 更多