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 form element to arguments passed to (private) validate hook #1793

Merged
merged 1 commit into from May 25, 2022

Conversation

simonihmig
Copy link
Contributor

See #1792

Copy link
Contributor

@jelhan jelhan left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me and I don't have concerns adding another argument on validate. It is not a public API. We have already changed it without major version as we have control over the validation addons using it.

I only have one question if we couldn't simplify the implementation.

@simonihmig
Copy link
Contributor Author

I only have one question if we couldn't simplify the implementation.

@jelhan in which way?

@@ -400,7 +409,7 @@ export default class Form extends Component {

return RSVP.resolve()
.then(() => {
return this.hasValidator ? this.validate(model) : null;
return this.hasValidator ? this.validate(model, this._element) : null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Somehow my review comment got lost. 😢

I'm wondering if we could pick up the form element from the event instead of tracking it through {{ref}}. The event listener is registered on the form element. Shouldn't the form element be available as event.target in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, indeed I had it this way, until I realized some existing test failed. It was one where we submit the form using the yielded submit action, and not a submit (browser) event. In which case we don't have event.target. That's why I also added the second test in this PR, which is replicating this very situation!

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch. 👏

@simonihmig simonihmig merged commit bb6e5ce into master May 25, 2022
@simonihmig simonihmig deleted the validate-form-arg branch May 25, 2022 15:42
@simonihmig simonihmig changed the title Add form element to arguments passed to validate hook Add form element to arguments passed to (private) validate hook May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants