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
mgr/dashboard: Add custom validators #21041
Conversation
4a2c3f7
to
a4e0a63
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@votdev Apparently CustomValidators
does not exist. Can you update your PR description example accordingly?
Validators as AngularValidators | ||
} from '@angular/forms'; | ||
|
||
export type Prerequisites = { // tslint:disable-line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a need to export this? Same for the function bellow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it's not necessary to export the Prerequisites type, this has been fixed now. But i would like to export the isEmptyInputValue
function because it is really helpful if you implement local validators in a form component. This is done in the RGW user form for example.
@ricardoasmarques The example has been adapted. |
41bb9c9
to
a1de489
Compare
} | ||
return isEmptyInputValue(control.value) ? {'required': true} : null; | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you extend this by a validateIf
function? A function that only validates a form element if the condition given is true like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this is needed? This validator is based on the origin required validator that simply tests for empty values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done to enhance the flexibility of this validator.
db2d13e
to
4ee15b1
Compare
ba50e16
to
66b1197
Compare
Signed-off-by: Volker Theile <vtheile@suse.com>
66b1197
to
20a2ec5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Add custom validators:
Example:
Signed-off-by: Volker Theile vtheile@suse.com