1

I have installed a module that adds another payment method, which has additional input options, and I want to make those options mandatory.

I've added a validator to validate #co-payment-form's input fields, as described in Magento's docs – Add custom validations before order placement.

I have added these attributes to the <select> element: data-validate="{required:true, 'validate-select':true}" and class="select validate-select".

And the validator looks like this:

define([
    'jquery',
    'mage/validation'
], function ($)
{
    'use strict';
    return {
        paymentFormSelector: '#co-payment-form',
        validate: function ()
        {
            const jqPaymentForm = $(this.paymentFormSelector).validation();
            return $(jqPaymentForm).valid();
        }
    };
});

Now, when I do not select anything and click on "Place Order"/"Submit Order", this validator gets called all right and the field gets a red error message.

How do I remove the message once the user has selected something?

I see that, for example, the mandatory fields of the shipping address form get all red upon trying to place an order, but once I start writing in such a field, the error message disappears at once.

How can I get the same for this custom validator?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.