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.

How to access field values in checkout via javascript

Solved

How to access field values in checkout via javascript

sdorobdev
Shopify Partner
2 1 0

I am writing a React/Javascript extension for the checkout page that will add a second Email contact field in order to get the user to enter the email address for the order twice. I want to compare the text in the Contact field that is rendered automatically by Shopify and in the new text field that the extension adds. If both fields are not the same, I will display a validation error.

 

I have the field and the validation error stuff working but I don't know how to extract the field of the Contact email address that is rendered automatically by the checkout page. Doing getElementById('email') is not allowed in React. Any help here would be appreciated.

Accepted Solution (1)

sdorobdev
Shopify Partner
2 1 0

This is an accepted solution.

For the other React noobies out there, I solved my problem by doing the following which automagically attaches to the email element. I can then just refer to 'email' to get the value.

const email = useEmail()

View solution in original post

Reply 1 (1)

sdorobdev
Shopify Partner
2 1 0

This is an accepted solution.

For the other React noobies out there, I solved my problem by doing the following which automagically attaches to the email element. I can then just refer to 'email' to get the value.

const email = useEmail()