manywho / ui-bootstrap

5 stars 3 forks source link

FLOW-845: Ensure state accurately reflects users input when clearing … #120

Closed ianhaycox closed 4 years ago

ianhaycox commented 4 years ago

…a date otherwise the next re-render uses a stale state value.

Essentially the issue is due to this line in input.tsx,

https://github.com/manywho/ui-bootstrap/blob/develop/js/components/input.tsx#L118

In the datetime component, when a user cleared the input, state.contentValue was set to null. The line above then uses model.contentValue - which is stale.

I didn't want to change this test in input.tsx because input is the parent of many components and really the fix should be isolated to the datetime component, rather than special case code in a generic component.

The fix is to therefore behave like the other child components and pass a '' state value when clearing the datetime input, so that the test above uses the correct state or model value.

A possible behaviour change might be that when saving a changed blank date the value stored may be '' rather than null if you never enter a date.

ianhaycox commented 4 years ago

To confirm there is no behaviour change as mentioned above, I created a test flow to save to a MySQL database with a datetime column. A blank string was correctly saved as a NULL in the db, as expected.