0

Is there any way I can display the validation message 'This is a require field' on page load on checkout page?

2 Answers 2

0

Yes, On the page load trigger click on submit button on current checkout page by jQuery. Then the required field will show the magento default validation messages.

0

Please Check Following Code and try :-

Create the file :

NameSpace/Module/view/frontend/layout/checkout_index_index.xml

In it, I will insert rules for validation name = 'company'.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
            <referenceBlock  name="checkout.root">
                <arguments>
                    <argument name="jsLayout" xsi:type="array">
                        <item name="components" xsi:type="array">
                            <item name="checkout" xsi:type="array">
                                <item name="children" xsi:type="array">
                                    <item name="steps" xsi:type="array">
                                        <item name="children" xsi:type="array">
                                            <item name="shipping-step" xsi:type="array">
                                                <item name="children" xsi:type="array">
                                                    <item name="shippingAddress" xsi:type="array">
                                                        <item name="children" xsi:type="array">
                                                            <item name="shipping-address-fieldset" xsi:type="array">
                                                                <item name="children" xsi:type="array">
                                                                    <item name="region_id" xsi:type="array">...</item>
                                                                    <item name="postcode" xsi:type="array">...</item>
                                                                    <item name="company" xsi:type="array">
                                                                        <item name="validation" xsi:type="array">
                                                                            <item name="min_text_length" xsi:type="number">0</item>
                                                                            <item name="max_text_length" xsi:type="number">9</item>
                                                                            <item name="letters-only" xsi:type="boolean">true</item>
                                                                            <item name="required-entry" xsi:type="boolean">true</item>
                                                                            <item name="max-words" xsi:type="number">2</item>
                                                                        </item>
                                                                    </item>
                                                                    <item name="fax" xsi:type="array">...</item>
                                                                    <item name="country_id" xsi:type="array">...</item>
                                                                    <item name="telephone" xsi:type="array">...</item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </argument>
                </arguments>
            </referenceBlock>
    </body>
</page>

How many validation rules Check this :-

min_text_length
max_text_length
max-words
min-words
range-words
letters-with-basic-punc
alphanumeric
letters-only
no-whitespace
zip-range
integer
vinUS
dateITA
dateNL
time
time12h
phoneUS
phoneUK
mobileUK
stripped-min-length
email2
url2
credit-card-types
ipv4
ipv6
pattern
validate-no-html-tags
validate-select
validate-no-empty
validate-alphanum-with-spaces
validate-data
validate-street
validate-phoneStrict
validate-phoneLax
validate-fax
validate-email
validate-emailSender
validate-password
validate-admin-password
validate-url
validate-clean-url
validate-xml-identifier
validate-ssn
validate-zip-us
validate-date-au
validate-currency-dollar
validate-not-negative-number
validate-zero-or-greater
validate-greater-than-zero
validate-css-length
validate-number
validate-number-range
validate-digits
validate-digits-range
validate-range
validate-alpha
validate-code
validate-alphanum
validate-date
validate-identifier
validate-zip-international
validate-state
less-than-equals-to
greater-than-equals-to
validate-emails
validate-cc-number
validate-cc-ukss
required-entry
checked
not-negative-amount
validate-per-page-value-list
validate-new-password
validate-item-quantity
equalTo

And you want to Get More-information Check this link :-

Magento 2.2 Input field validation on Checkout page

THANKS.

2
  • My validation is working good (Upon clicking Place Order button it is displaying). I just need to display the message "This is a require field" on the page load by default.
    – ASR
    Commented Jul 28, 2020 at 8:39
  • check this link - magento.stackexchange.com/a/143614/85907. This link is without any button click show validation message. Commented Jul 28, 2020 at 8:52

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.