hyva-themes / magento2-react-checkout

Highly Customizable Checkout for Magento 2, Built with React.
BSD 3-Clause "New" or "Revised" License
180 stars 54 forks source link

Add defaultValue parameter for Textinput #253

Closed vinodsowdagar closed 2 years ago

vinodsowdagar commented 2 years ago

Certain payment methods i am currently implementing need extra information from the user. Sometimes this information is already available in the billing address, so i want to put a default value in the Textinput based on certain information in the billing address so the user only has to check if it is correct and change it if he wants.

Currently this is not possible with the Textinput component, because the defaultValue is hardcoded as an empty string. Let me know if this change is correct/wanted. If not i can always create my own Textinput component, but i thought this might be useful to others as well.

rajeev-k-tomy commented 2 years ago

The TextInput component is basically a formik field. So to give a default value for a formik field is pretty simple. You need to provide the default value in the initialValues defined in every FormikProvider* components. If your default value depends on a certain conditions, then you should set the formik state using useEffect from FormikProvider* component or any other suitable component. This is the right approach when it comes to setting the default value for a formik field.

vinodsowdagar commented 2 years ago

@rajeev-k-tomy Hi, thanks for the feedback. In this case i will follow your advice and close this PR.