You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

Adding new fields with form validation

edited Feb 6, 2020 8:09PM in Commerce

Summary

Need to create 1 new field and make it required... but the JavaScript code I need to edit is out of the box.

Content

Hello all, 

I need to create a new field on a checkout page that is validated on an out of the box JavaScript file. I have tried making an extendedjs file and put the form validation code there, however, the out of the box code overwrites it. Is there any way to edit the out of the box JavaScript file or find it anywhere? 

fyi: I am using knockout js. 

Version

19D

Code Snippet

//code from the out of the box js file
else if (i.order().shippingAddress().validateForShippingMethod()) 
{
      i.order().shippingAddress().firstName() == undefined && i.order().shippingAddress().firstName(""), 
      i.order().shippingAddress().lastName() == undefined && i.order().shippingAddress().lastName(""), 
      i.order().shippingAddress().address1() == undefined && i.order().shippingAddress().address1(""), 
      i.order().shippingAddress().city() == undefined && i.order().shippingAddress().city(""), i.order().shippingAddress().phoneNumber() 
      == undefined && i.order().shippingAddress().phoneNumber("");

      if (i.cart().shippingAddress() == "" || i.cart().shippingMethod() == "" || 
        i.cart().isShippingAddressChanged(i.order().shippingAddress().toJSON(), i.cart().shippingAddress().toJSON())) 
        i.order().selectedShippingOption(""), $.Topic(r.topicNames.CHECKOUT_SHIPPING_ADDRESS_UPDATED).publish();
Tagged:

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!