Validating custom input field on product page

Validating custom input field on product page

fpiskur
Shopify Partner
2 0 0

I've added a custom select field on my product page and removed the 'novalidate' attribute from `buy-buttons.liquid` file. Now the validation works when I click 'Add to cart', but it still doesn't work on 'Buy it now'. I've seen another question here about the same problem a few years back and the only answer was asking if they can just listen for a click event on the 'Buy it now' button. I've tried that but didn't work. Also, who says it will always be a 'click' event that triggers the button? Anyway... Is there a solution for this? It seems ridiculous to me to have the abbility to add custom fields and have them be required for adding to cart but not for buying now.

Replies 3 (3)

Guleria
Shopify Partner
3187 620 891

Hello @fpiskur ,

 

I never found a solution for it.
The alternative i use to solve it is, don't show the buy now button until custom fields have values.  

Thanks

- If helpful then please Like and Accept Solution.
- Want to modify or custom changes or bug fix on store Hire me. - Email: guleriathakur43@gmail.com - Skype: navrocks1 ,
- Try GEMPAGES a great page builder
- Support me PayPal
fpiskur
Shopify Partner
2 0 0

Where did you add the code for hiding the buy button? I can't remember exactly where I tried but it didn't work for me. 

let buyBtn = document.querySelector('.shopify-payment-button__button');
buyBtn.style.display = 'none';

 I even tried wrapping it inside a 'load' event listener.

alexrom27
Visitor
2 0 0

You can just de-select it in the theme settings. When in customise mode- click on the button section and deselect 'dynamic' buttons.