0

I created a new attribute(favouriteStore - Enum of String datatype) in standard 'profile' object and added it to the account creation page in storefront. Now, I couldn't get the user selected picklist value from ISML to js. I tried the below code, and it is returning undefined. Could you please help me with this.

Below is the isml code: 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 code: 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>

All other string fields are getting saved, just this favouriteStore picklist field is returning undefined. Could you please guide me where I'm going wrong with this.

Thanks in Advance!

  • 1
    You have misspelt 'favourite' in the field `registrationForm.customer.favoriteStore.value` – AlBlue Jan 07 '21 at 13:19
  • @AlBlue Thanks for your response! Sorry, my bad. I corrected it. But, the picklist field is still blank. Could you please let me know if there might be any other issue with the code – Sri Pavithra Chellamuthu Jan 08 '21 at 06:46

1 Answers1

0

As AlBlue mentioned, the issue seems to be that you didn't spell favouriteStore the same way in the ISML and the DWScript. (JavaScript)

That said, you should ensure that you also have form XML defined for that field. For example, you should add it to your storefront cartridge's cartridge/forms/default/profile.xml file. (or override the one from app_storefront_base)

sholsinger
  • 3,028
  • 2
  • 23
  • 40
  • Thanks for your response! Even after updating it, am facing issue.. The value is not saved in the object level. I've also added the xml code. Could you please check and let me know if there is any other issue. – Sri Pavithra Chellamuthu Jan 08 '21 at 06:47
  • @AIBlue and sholsinger The issue was with the onchange="getSelected(this)" in ISML. After removing that and adding to select tag, the save worked! One more question I have is, I have to replace all comma (,) with break (
    ) or new line in a string. I used replace method from String Class. But, it's not working as expected. Could you please let me know the syntax on how to use it? Thanks a lot for your help!
    – Sri Pavithra Chellamuthu Jan 08 '21 at 11:42