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

feat: Forms: Add reset validation functionality to form and form element [GAUD-6979] #4983

Merged
merged 10 commits into from
Sep 24, 2024

Conversation

margaree
Copy link
Contributor

@margaree margaree commented Sep 18, 2024

Jira ticket

This adds reset functionality to both a d2l-form and FormElementMixin. I'd originally looked at adding it to the FormMixin but that got complicated because of potential for nesting of forms and how some functionality lives in Form vs others in FormMixin. I can re-look at that, but at the moment there's nothing just using FormMixin.

This can be tested on the form demo page.

To do:

  • tests
  • documentation
  • Add flag

Copy link
Contributor

Thanks for the PR! 🎉

We've deployed an automatic preview for this PR - you can see your changes here:

URL https://live.d2l.dev/prs/BrightspaceUI/core/pr-4983/

Note

The build needs to finish before your changes are deployed.
Changes to the PR will automatically update the instance.

this._errors = [];

this.childErrors.forEach((_, ele) => {
if (!isCustomFormElement(ele)) return;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A case (?) that wouldn't be covered is if the child error is a native element. I don't know if that's actually a thing we deal with.

components/form/form-element-mixin.js Show resolved Hide resolved
@margaree margaree changed the title feat: Forms: Add reset functionality to form and form element [GAUD-6979\ feat: Forms: Add reset functionality to form and form element [GAUD-6979] Sep 18, 2024
@margaree margaree marked this pull request as ready for review September 18, 2024 13:04
@margaree margaree requested a review from a team as a code owner September 18, 2024 13:04
@margaree margaree changed the title feat: Forms: Add reset functionality to form and form element [GAUD-6979] feat: Forms: Add reset validation functionality to form and form element [GAUD-6979] Sep 18, 2024
components/form/test/form-element.test.js Outdated Show resolved Hide resolved
components/form/test/form-element.test.js Outdated Show resolved Hide resolved
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties);

this.addEventListener('d2l-dialog-close', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Probably worth a unit test that covers this case?

this.addEventListener('d2l-dialog-close', () => {
const dialogAncestor = findComposedAncestor(
this,
(node) => { return (node?.tagName?.includes('D2L-DIALOG')); }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'd want to do this for all dialogs, yeah? Like including d2l-dialog-fullscreen or other dialog components that might extend the DialogMixin.

Copy link
Member

Choose a reason for hiding this comment

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

The .includes( should cover that?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh good point. I glossed over that. So it would just be anyone (like LCS) that might have extended the mixin for their own component. Maybe they're on their own to reset their forms.

Copy link
Member

@dlockhart dlockhart Sep 18, 2024

Choose a reason for hiding this comment

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

Wonder if something like node.prototype instanceof DialogMixin would work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still looking into it but so far haven't been able to get that to work

Copy link
Contributor

Choose a reason for hiding this comment

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

I know in a couple other places we've set a property that can be checked, which seems kinda hacky. What Dave proposed seems much nicer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't been able to get anything along the lines of the node.prototype instanceof DialogMixin check working. I can get setting a property on dialog mixin and checking for that working. Do we want to go through with the property option? Any other ideas that I maybe haven't tried?

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I feel like a _isDialogMixin = true "private" variable would be slightly more resilient than the tag name check, but am good with either.

components/form/form.js Outdated Show resolved Hide resolved
Co-authored-by: Dave Lockhart <[email protected]>
@margaree margaree merged commit 856f158 into main Sep 24, 2024
6 checks passed
@margaree margaree deleted the form-reset branch September 24, 2024 13:30
Copy link

🎉 This PR is included in version 3.43.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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.

3 participants