Skip to content

Trigger validation using Form Field #5943

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

Merged
merged 21 commits into from
Mar 30, 2023
Merged

Trigger validation using Form Field #5943

merged 21 commits into from
Mar 30, 2023

Conversation

g4rry420
Copy link
Contributor

@g4rry420 g4rry420 commented Feb 11, 2022

Signed-off-by: GurkiranSingh gurkiransinghk@gmail.com

What does this PR do?

This pr provides the functionality to trigger validation using the Form Field.
Please, feel free to point out any mistakes.

Where should the reviewer start?

Form.js, FormField.js

What testing has been done on this PR?

Test using the TriggerValidationUsingFormField.js storyName. I have tested these scenario:

  • When component is mounted,
  • One FormField 's validateOn is different than another
  • Basic functionality of validate on Form level also works

How should this be manually tested?

Using the TriggerValidationUsingFormField.js

Do Jest tests follow these best practices?

  • screen is used for querying.
  • The correct query is used. (Refer to this list of queries)
  • userEvent is used in place of fireEvent.
  • asFragment() is used for snapshot testing.

Any background context you want to provide?

What are the relevant issues?

#5913

Screenshots (if appropriate)

Do the grommet docs need to be updated?

Yes

Should this PR be mentioned in the release notes?

Is this change backwards compatible or is it a breaking change?

backwards compatible

@MikeKingdom MikeKingdom self-assigned this Feb 15, 2022
Copy link
Collaborator

@MikeKingdom MikeKingdom left a comment

Choose a reason for hiding this comment

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

A couple of small comments, otherwise I think the functionality is good.

Signed-off-by: GurkiranSingh <gurkiransinghk@gmail.com>
Signed-off-by: GurkiranSingh <gurkiransinghk@gmail.com>
Copy link
Collaborator

@MikeKingdom MikeKingdom left a comment

Choose a reason for hiding this comment

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

Thanks!

@g4rry420
Copy link
Contributor Author

Any updates on this pr @ericsoderberghp @ShimiSun ?

@ericsoderberghp
Copy link
Contributor

Apologies for such a long delay in responding to this. Thanks for the new story. I tried interacting with it in the following manner:

  • click on the Blur field
  • tab to the Submit field - no validation is shown for the Blur field, I would have expected the "required" validation to be shown
  • tab to the Change field - no validations are shown, which seems correct
  • shift tab back to the Submit field - no validation issues are shown for the Change field, I was expecting it to show "required"
  • shift tab back to the Blur field - no validations are shown, which seems correct
  • type "a" - the "must be >1 character" validation shows up, this seems like it is being shown based on a change rather than a blur, which doesn't seem correct.

I didn't attempt to sift through the code to pinpoint where the issues might lie. But, I figured this testing might be helpful to start with.

@g4rry420
Copy link
Contributor Author

Thank you for pointing out these issues.

One more thing I notice, Suppose, there are 3 Form fields wrapped around the form component, if the user specifies the Form level validate ="change" prop and also specifies the Form Field level validateOn="blur" prop only on 1 form field, we would expect that the other two form fields automatically gets change validation behaviour. Is this the correct behaviour ?

@jcfilben jcfilben added the needs attention To alert grommet team that a PR has been waiting for the author for a while label Sep 28, 2022
Signed-off-by: GurkiranSingh <gurkiransinghk@gmail.com>
@g4rry420
Copy link
Contributor Author

@ericsoderberghp It's been a long time since this pr is reviewed. I will really appreciate your's and Grommet maintainers efforts to take some time out of your busy schedule to review this pr.

One more thing I notice, Suppose, there are 3 Form fields wrapped around the form component, if the user specifies the Form level validate ="change" prop and also specifies the Form Field level validateOn="blur" prop only on 1 form field, we would expect that the other two form fields automatically gets change validation behaviour. Is this the correct behaviour ?

Apart from this scenario, I don't see any issues with this pr. Please, let me know if you find any unexpected behaviour. Thanks :)
cc @ShimiSun

@jcfilben
Copy link
Collaborator

jcfilben commented Nov 2, 2022

Hi @g4rry420 sorry for the long delay here. Thanks for reaching out to get some eyes on this again! I think this is super close to the finish line.

The behavior looks good to me, I'm in the process of digging into the code a bit more to make sure things look good there.

One more thing I notice, Suppose, there are 3 Form fields wrapped around the form component, if the user specifies the Form level validate ="change" prop and also specifies the Form Field level validateOn="blur" prop only on 1 form field, we would expect that the other two form fields automatically gets change validation behaviour. Is this the correct behaviour ?

Yes, I think that is the correct behavior. If validation is defined at the FormField level then that should override the Form level but only for that field. The other fields should align with the Form level validation.

g4rry420 and others added 2 commits November 2, 2022 22:49
…lt use the validate prop value from the Form

Signed-off-by: GurkiranSingh <gurkiransinghk@gmail.com>
@g4rry420
Copy link
Contributor Author

g4rry420 commented Nov 4, 2022

@jcfilben Above discussed behavior is also implemented. Please, let me know if you see any issues :)

@jcfilben
Copy link
Collaborator

jcfilben commented Nov 4, 2022

@jcfilben Above discussed behavior is also implemented. Please, let me know if you see any issues :)

Tested this out and storybook and so far it is looking good! Still working my way through the code. In the meantime I think it would be nice to have some unit tests for this.

Copy link
Collaborator

@jcfilben jcfilben left a comment

Choose a reason for hiding this comment

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

Thanks for adding tests! Just a minor comment on the story. Also looks like the bundlesize needs increased. This can be done in the package.json file. Just bump it up slightly to 144 kB.

…example

Signed-off-by: GurkiranSingh <gurkiransinghk@gmail.com>
@g4rry420 g4rry420 requested review from jcfilben and removed request for ericsoderberghp November 10, 2022 02:15
Copy link
Collaborator

@jcfilben jcfilben left a comment

Choose a reason for hiding this comment

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

Looks good!

@jcfilben jcfilben added PRty Biweekly PR reviews by grommet team with hoping of closing such PRs and removed needs attention To alert grommet team that a PR has been waiting for the author for a while labels Mar 30, 2023
Copy link
Contributor

@ericsoderberghp ericsoderberghp left a comment

Choose a reason for hiding this comment

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

Apologies for the long delay getting this in.

@ericsoderberghp ericsoderberghp merged commit 0c39b90 into grommet:master Mar 30, 2023
@ericsoderberghp
Copy link
Contributor

I think the new story should be omitted from Chromatic snapshot evaluation, since it's there just for interaction. We can take care of this post-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PRty Biweekly PR reviews by grommet team with hoping of closing such PRs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants