Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Added a defaultValue attributte #44

Closed
wants to merge 3 commits into from

Conversation

UsmanJ
Copy link

@UsmanJ UsmanJ commented Feb 14, 2020

Had to add a defaultValue attribute and access the defaultValue object being passed through on the Input because the Input is a product of the mapping of dateInputItems. This is because otherwise when you go back to a page using the DateInput component, the values are not mapped correctly due to it using a list.

@UsmanJ UsmanJ closed this Feb 14, 2020
@UsmanJ
Copy link
Author

UsmanJ commented Feb 14, 2020

Sorry - got broken tests. Will fix and then reopen. In the meantime if you think there is an alternative way of achieving this then do let me know.

@UsmanJ UsmanJ reopened this Feb 14, 2020
@andymantell
Copy link
Collaborator

@UsmanJ Are you still using Formik? And are you using the latest version of the component I wrote to wrap the date fields for compatibility with Formik? No worries if not, just trying to get a better understanding of what your setup is here

@andymantell
Copy link
Collaborator

@UsmanJ This is the code for the DateField wrapper I had started:

https://gist.github.com/andymantell/278e67a9b4617e54fe3ddfbf858d0b37

@andymantell
Copy link
Collaborator

Basically, this is at the heart of issue #4

Using the date input with a form library like Formik causes problems because it is not able to handle a top level value prop. You need to wrap the component and create an "adapter" of sorts. We should document this...

@UsmanJ
Copy link
Author

UsmanJ commented Feb 14, 2020

@andymantell Yes we are continuing to use Formik. Oh I see, so rather than using FormField, you use DateField for the Date component to overcome the issue in question?

@andymantell
Copy link
Collaborator

Yes exactly that - what the DateField wrapper does is present those three fields as a single field to Formik rather than the separate date components. If you look at the later versions of the code we pushed you should see this working. Doesn't have to be done that way, but that was how I had tackled it initially.

The Date component is a tricky one though - I think the issue with your proposal here is that it makes assumptions about the surrounding form code that may not hold true for everyone. It's a seemingly simple change but it's making my brain hurt thinking about what issues it may cause. I think probably what I need to do is to set up a demo with Formik as well as maybe another popular form library, and no library at all and see if there's a way to make this component work well with all of them.

Perhaps the DateField wrapper actually lives in this repository alongside the base component...

@UsmanJ
Copy link
Author

UsmanJ commented Feb 14, 2020

Yes I agree, and tbh I did expect you to have this hesitation towards adding a defaultValue to the date component and was hoping you'd suggest an alternative way as I also didn't think it was the mode ideal route to take.

I think adding the DateField in this repository is a good idea. I'll give this way a go after lunch and will let you know how it goes.

@andymantell
Copy link
Collaborator

That'd be great if you could let me know how it goes. We can use that gist as the starting point and iterate from there. I don't mind adding Formik specific wrappers to this repository so long as the base components remain as framework agnostic as possible.

@UsmanJ
Copy link
Author

UsmanJ commented Feb 14, 2020 via email

@andymantell andymantell closed this Mar 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants