-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Simplify forms. #6322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify forms. #6322
Conversation
|
I haven't ported any examples or tests over yet this is just to demonstrate the API. |
71b6675 to
68ffcb8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cute
|
Looks pretty good. I guess I would have expected the |
|
Yeah this is just part 1, I haven't figured out what part 2 looks like. I've updated a few of the examples and this definitely doesn't make them shorter, which is sad. Especially the InputValue/String conversion is painful. |
|
We could make a subclass of FormField that knew about InputValue and talked to you in Strings. |
|
Yeah, that would help. |
67cbd65 to
ba13a68
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My motivation with the FormField stuff was to remove the need for the app developer to manage any sort of intermediate framework objects for form data. They would manage their app-specific data struction (e.g. Person) and the framework holds the InputValues and knows how to update the app-specific structure automatically.
My original vision was something that let me do:
new Input(
labelText: 'Name',
mapsTo: person#name
)
then person.name is the Real Truth for what is shown in the Input, and is updated whenever the Input changes. Dart doesn't quite let us do that, so supplying a setter was the next-best thing. There's a proposal for adding tear-offs to Dart, but AFAIK it isn't official adpoted. If it were, we could do:
new Input(
labelText: 'Name',
setter: person#name=
)
which seems close enough. IMO that's the direction we should be heading.
Maybe we should have a sub-class of Input that allows you to do the short-hand with conversion between InputValue and String, rather than a separate FormField argument to Input?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem is that the value of an Input (an InputValue) has a selection, but the data model is a String, so it can't be the exclusive ground truth.
Another complication is with forms that you prepare and then submit (vs those that are "live"). For example the expansion panel example used to save even if you hit "Cancel"; this patch attempts to fix that.
But yeah, I don't like that you have to have all these FormField objects everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem is that the value of an Input (an InputValue) has a selection, but the data model is a String, so it can't be the exclusive ground truth.
The selection is a property of the editor, not the data model. I think as an app developer, I'd just want the framework to manage that behind the scenes and not tell me about it (in the general case).
Another complication is with forms that you prepare and then submit (vs those that are "live"). For example the expansion panel example used to save even if you hit "Cancel"; this patch attempts to fix that.
I could see that also being fixed by providing a temp object, which gets swapped with the final object on submit. e.g. use tempPerson everywhere, then in onSubmit just do finalPerson = tempPerson;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that seems reasonable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another issue is how to handle external changes in the model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like your original vision but I don't see how to make it work with external changes to the model. It'd need some sort of scaffolding around it.
I'm not sure where to go with my patch here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The selection is a property of the editor, not the data model.
This is an interesting observation. It's tricky because the selection is tied to the string in many ways. What would one expect to happen if we had two text fields backed by the same string, such that editing one changed the other — should the selection be mirrored in both? What happens if the selection in one becomes invalid because of edits in the other?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started refactoring Input so that the InputValue was kept there and not in FormField, but that won't work. It would prevent you from changing the selection (e.g. because you want to start the form with a word selected so it can be easily replaced).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If:
- data can't be a plain dart object because otherwise how could it notify the form of changes, and
- we want to have an adapter from string to InputValue
maybe the solution is that the Form holds an object that contains FormFields which have an API for Inputs to read out of an an API for users to write into. I'll have to think more on what that would look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. Some sort of observable view-model.
ba13a68 to
763242a
Compare
This does not yet do anything about associating the values directly with the forms.
763242a to
3e16623
Compare
| enum _Location { | ||
| Barbados, | ||
| Bahamas, | ||
| Bermuda |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpcomplete the changes in this PR for this file attempt to implement the save/cancel buttons (previously they were bogus). It'd be interesting to see how this would look under your patch (it's not great under this one).
| TextFieldDemoState createState() => new TextFieldDemoState(); | ||
| } | ||
|
|
||
| class PersonData { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mpcomplete similarly these changes were to actually implement the "SUBMIT" button which previously was dummy. It also makes the lifeStory be saved (previously it wasn't).
|
I plan on closing this branch without landing it but first I want to go through and make sure I've applied all the minor fixes I made. I plan on waiting after @mpcomplete is done with his current set of changes to forms. |
This does not yet do anything about associating the values directly with the forms.