Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

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
4299 825 1189

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

- Elevate Your Store with Expert Shopify Services. Email: guleriathakur43@gmail.com - Need a quick fix or a tailored customization? I’ve got you covered.
- Looking to enhance your pages? Try GEMPAGES- a powerful drag & drop page builder.
- Let’s make your store stand out. Get in touch today!
- My Apps: Productify Groups – Smart product grouping made easy.
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.