Fix for fb: group with DateTime or TimeOfDay value and a validator as array#503
Fix for fb: group with DateTime or TimeOfDay value and a validator as array#503DanyUP wants to merge 2 commits into
Conversation
…and a validator as array
Summary of ChangesHello @DanyUP, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a bug in FormBuilder that prevented validators from being applied to DateTime and TimeOfDay form controls when defined using array syntax. The fix ensures that validators are correctly passed during FormControl creation, and new unit tests have been added to confirm the expected behavior. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a bug where validators were not being applied to DateTime and TimeOfDay controls when using the array syntax in fb.group. The fix correctly passes the validators to the FormControl constructor, which is the right approach. The change is supported by new unit tests that verify the fix for both DateTime and TimeOfDay. The fix is correct and the tests are relevant. I've added a few suggestions to improve the new test code by using more idiomatic matchers, which will make them more concise and robust.
| expect( | ||
| form.control('control') is FormControl<DateTime>, | ||
| true, | ||
| reason: | ||
| '${form.control('control').runtimeType} is not instance of FormControl<DateTime>', | ||
| ); |
There was a problem hiding this comment.
For type checks in tests, it's more idiomatic to use the isA<T>() matcher. It provides better error messages on failure, especially if the control is null.
| expect( | |
| form.control('control') is FormControl<DateTime>, | |
| true, | |
| reason: | |
| '${form.control('control').runtimeType} is not instance of FormControl<DateTime>', | |
| ); | |
| expect(form.control('control'), isA<FormControl<DateTime>>()); |
| expect( | ||
| form.control('control').validators.length, | ||
| 1, | ||
| reason: 'incorrect validators length' | ||
| ); | ||
| expect( | ||
| form.control('control').validators[0], | ||
| requiredValidator, | ||
| reason: 'not set required validator' | ||
| ); |
There was a problem hiding this comment.
You can simplify these two assertions into a single one by comparing the validators list directly. This is more concise and checks both the length and the content of the list.
| expect( | |
| form.control('control').validators.length, | |
| 1, | |
| reason: 'incorrect validators length' | |
| ); | |
| expect( | |
| form.control('control').validators[0], | |
| requiredValidator, | |
| reason: 'not set required validator' | |
| ); | |
| expect(form.control('control').validators, [requiredValidator]); |
| expect( | ||
| form.control('control') is FormControl<TimeOfDay>, | ||
| true, | ||
| reason: | ||
| '${form.control('control').runtimeType} is not instance of FormControl<TimeOfDay>', | ||
| ); |
There was a problem hiding this comment.
For type checks in tests, it's more idiomatic to use the isA<T>() matcher. It provides better error messages on failure, especially if the control is null.
| expect( | |
| form.control('control') is FormControl<TimeOfDay>, | |
| true, | |
| reason: | |
| '${form.control('control').runtimeType} is not instance of FormControl<TimeOfDay>', | |
| ); | |
| expect(form.control('control'), isA<FormControl<TimeOfDay>>()); |
| expect( | ||
| form.control('control').validators.length, | ||
| 1, | ||
| reason: 'incorrect validators length' | ||
| ); | ||
| expect( | ||
| form.control('control').validators[0], | ||
| requiredValidator, | ||
| reason: 'not set required validator' | ||
| ); |
There was a problem hiding this comment.
You can simplify these two assertions into a single one by comparing the validators list directly. This is more concise and checks both the length and the content of the list.
| expect( | |
| form.control('control').validators.length, | |
| 1, | |
| reason: 'incorrect validators length' | |
| ); | |
| expect( | |
| form.control('control').validators[0], | |
| requiredValidator, | |
| reason: 'not set required validator' | |
| ); | |
| expect(form.control('control').validators, [requiredValidator]); |
Connection with issue(s)
Close #428
Solution description
Fixes a bug with FormBuilder: when creating a from group with a DateTime or TimeOfDay value and a validator using array syntax, the validator is not added to the created FormControl.
For example, when creating a form group like this:
the resultant FormControl (named 'control' in the example) is missing the validator.
Screenshots or Videos
To Do