Skip to content
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

Add submitPreventDefault to Formless when using forms #80

Merged
merged 6 commits into from
Nov 18, 2021
Merged

Add submitPreventDefault to Formless when using forms #80

merged 6 commits into from
Nov 18, 2021

Conversation

chiroptical
Copy link
Contributor

@chiroptical chiroptical commented Nov 14, 2021

What does this pull request do?

Closes #79. In the examples, this is handled by not using form but many people will reach for what they are familiar with. It is quite confusing when you run into this especially as a beginner to frontend development. Therefore we suggest the addition of F.submitPreventDefault and make the appropriate changes to the readme to avoid this confusion altogether. Additionally, we add the example code in the readme to the examples directory.

Where should the reviewer start?

I added some comments on where to start your review 😄

How should this be manually tested?

You can bundle the examples with spago -x example/example.dhall bundle-app --to ./dist/app.js to launch the "readme" example and see the behavior. You can also modify the onSubmit \_ -> F.submit to see that the page refreshes.

Other Notes:

It might be useful to modify the existing examples to now use form elements and the F.submitPreventDefault function.

src/Formless/Action.purs Outdated Show resolved Hide resolved
Comment on lines +94 to +96
HH.form
[ HE.onSubmit F.submitPreventDefault
]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use submitPreventDefault in the readme example to avoid confusion

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do this in a follow up PR if you'd like, but we really should switch all forms to be written this way

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking to do that follow up PR, if that's not a problem

Comment on lines 113 to 118
In formless, if you use a default form you would notice a page refresh when submitting the form.
In the other examples, this is avoided by not using a form element. In this example, we use
a special function F.submitPreventDefault to avoid the page refresh.

You can download the examples and replace F.submitPreventDefault with
\_ -> F.submit to see the difference.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text explaining how submitPreventDefault changes the behavior of them form and how to modify the example is probably worth reviewing as well.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be removed, probably, as you really ought to just use forms this way in general. I think it'd be better to add documentation to submit that says it can be used to submit the form imperatively, but that if you want to capture the form submission event and submit your form that you should use submitPreventDefault

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We introduced submitPreventDefault to avoid the breaking change. Maybe it could be changed to work the other way around in a future major release?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I’d rather have ‘submit’ and ‘submit_’ using the usual Halogen naming conventions in the future!

Copy link
Owner

@thomashoneyman thomashoneyman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @chiroptical! This is looking good, just have a few comments.

@thomashoneyman thomashoneyman merged commit 657225e into thomashoneyman:main Nov 18, 2021
@chiroptical chiroptical deleted the add-submit-prevent-default branch November 18, 2021 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a helper function to submit a form and call preventDefault on the event
3 participants