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

The Bar Rating Component always has the Validator required:true, even if we do not set it to be required, due to component logic #116

Open
1 task done
BenPKore opened this issue Sep 13, 2024 · 2 comments

Comments

@BenPKore
Copy link

I am submitting a bug

  • Bug Report

What is the expected behavior?

When we set in our form control for the control to not be required, then the bar rating component should not have a required:true error.

What is the current behavior?

When we do not add the required directive to the bar-rating, it still acts as required, because if the bar-rating value is 0, there is some logic in the component that sets the errors: { required: true }

What are the steps to reproduce?

Link to stackblitz: https://stackblitz.com/edit/ngx-bar-rating-er6r7z?file=src%2Fmain.ts,src%2Findex.html

What is the use-case or motivation for changing an existing behavior?

The component is always required and it should not be.

Which versions are you using for the following packages?

7.0.1

Angular:
ngx-bar-rating:

Is there anything else we should know?

I think it might be this validate() method? If the bar rating value is !0, then it will set required:true... But we should be able to have 0 as the rating is not required.

validate(c: UntypedFormControl): { required: boolean } | null {
    return (this.required && !c.value) ? { required: true } : null;
  }
@MurhafSousli
Copy link
Owner

So you mean we should use c.value != null instead?

@BenPKore
Copy link
Author

BenPKore commented Oct 1, 2024

Hello, apologies for the late reply!

Yes I believe that would resolve the issue.

I also noticed that this.required would always evaluate to true as it's defined as a function rather than a simple boolean variable but I'll leave that with you :)

Thanks!

Screenshot 2024-10-01 104619

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

No branches or pull requests

2 participants