cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically add/remove validation based on radio Button choice (checkout)

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Programmatically add/remove validation based on radio Button choice (checkout)

I have two radio buttons: Private and Business  when the user select private button I and to remove the validation from an specific input field: Full name, and if user select private again, it just come it back. Is there a way to programmatically change if the field is required? I added this fields to the checkout using layout processor:

 

        $customField = [
            'component' => 'JCustom_FullName/js/togglepersontype',
            'config' => [
                'customScope' => 'shippingAddress',
                'template' => 'ui/form/field',
                'elementTmpl' => 'JCustom_FullName/radio'
            ],
            'dataScope' => 'shippingAddress' . '.' . $customAttributeCode,
            'label' => __('Tipo de entidade:'),
            'provider' => 'checkoutProvider',
            'sortOrder' => 0,
            'validation' => [
                'required-entry' => false
            ],
            'options' => [],
            'filterBy' => null,
            'customEntry' => null,
            'visible' => true,
        ];

 

What happens when a field is filled with required-entry => true? Can I change it to false/true using JavaScript?

1 REPLY 1

Re: Programmatically add/remove validation based on radio Button choice (checkout)

Hello @syssolutions 

 

https://devdocs.magento.com/guides/v2.3/ui_comp_guide/concepts/ui_comp_linking_concept.html

 

please check above link for same.

 

Hope it will help you


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer