Closed SpringSan closed 1 year ago
I see other field have the Property 'value'
@SpringSan That's an interesting problem, while the form state is not meant to be directly manipulated by providing the value, it exists to be handled by form field state change.
I can however try to add additional state updater binding that to the value prop and updating the form state internally.
What you can do is instead of just having the date object as a state variable, have the entire initial form values as the state, and then when data from API changes try to update the initial values and see if that updates your date field.
Note: While trying this, make the enableReinitialize={true}
in form wrapper
Let me know if that works.
I will try to test the use case whenever I can spare some free time this weekend.
Your suggestion that update the initial values i have tried. It don't works. But if you update the initial values the date selector's value will update, however the field value that show never change. Also i think the function 'setFeildValue' can update the field value.
And the function onDateChange can't work
@SpringSan Yes, I get the point. That is only changing the values for submission and not updating the base date picker's value, hence not the updated value in UI. What we could do is that If an existing value exists from the values[name] == name (date picker) as an initial value we can update that from the start or whenever values[name] for date changes. Kind of like an initial setter and onChange trigger.
useEffect(() => {
if (values[name] && moment(values[name).isValid()) {
setFieldValue(name, values[name]);
}
}, []);
@SpringSan Something like this, which might not be the best solution at the moment can make things work.
useEffect(() => { if (values[name] && moment(values[name).isValid()) { setFieldValue(name, values[name]); } }, []);
@SpringSan Something like this, which might not be the best solution at the moment can make things work.
Hey,I try to add the code to \node_modules\@superforms\superforms-rn\src\Form\FormDateSelector , but it doesn't works. And it seems never go into this code.
useEffect(() => { if (values[name] && moment(values[name).isValid()) { setFieldValue(name, values[name]); } }, []);
@SpringSan Something like this, which might not be the best solution at the moment can make things work.
Hey,I try to add the code to \node_modules\@superforms\superforms-rn\src\Form\FormDateSelector , but it doesn't works. And it seems never go into this code.
Hmm, it should have. I will debug this later in the week. Maybe you can add values [name]
in the dependency array.
Ok . Thanks a lot
Describe the bug When my data from api change but the value which the field show is not change. So i want to know how to change the value the field show except press the date selector. Also i bind the property 'date' to the state, the date selector change the date but it can't show in the field. Please help me , thank you. '' To Reproduce Steps to reproduce the behavior:
Expected behavior The date field value can change by value change.
Screens hots
Smartphone (please complete the following information):