0

I have a custom checkout module and as part of the design I need to run some custom JS when the shipping address form is valid. By default the form is validated when all the fields have values. I have been unable to find what triggers this validation to run.

I would like to prevent this validation until a user clicks a submit button and if the form is valid I run my custom js.

I have copied over the shipping.js from vendor/magento/module-checkout/view/frontend/web/js/view/shipping.js and added a console log to all of the functions to get an understanding of when each is fired but they only appear to do so when the Next button is clicked. What file controls the validation of the form?

asked Feb 13, 2023 at 18:05

1 Answer 1

0

The checkout is managed mainly with knockout.js

The functions are only called in certain cases if all conditions are met.

The checkout is one of the most complex part of magento and an understanding of knockout.js is necessary

All form validation rules are in the following file :

Magento_Ui/web/js/lib/validation/rules.js

You can look at this repository to understand how it works:

https://github.com/sohelrana09/modified-checkout

answered Feb 14, 2023 at 10:12
3
  • Thanks for your response. That provides some good context. You mention "The functions are only called in certain cases if all conditions are met." Where are the functions that are called? Currently I am okay with when they are called but I would like to add to them. I can't find what functions are called once the form is filled out, namely the function(s) that checks for it being validated and shows the shipping options Commented Feb 15, 2023 at 14:44
  • Probably this file : vendor/vertexinc/module-address-validation/view/frontend/web/js/view/checkout/shipping/address-validation.js You can find this file name for the delivery & billing address validation. Commented Feb 17, 2023 at 10:39
  • If answer help, please upvote and accept as solution, so it will help other in community. Commented Mar 3, 2023 at 11:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.