Angular 9 form validation with dropdowns (ngseelct) and selectitemlist label checkbox for
I have a from with dropdown ngselect and checkbox list calss fom checklabel and inout checkboxes on buton click show validation erors.so how to display eror .in dropdowns deafult value is -1.so i user didnt select any dropdown a=or checkbox display erors
Rajkiran SwainPosted Apr 29, 2023, 5:50 AM
Create a form in your component:
In this example, we are creating a form with two fields: a dropdown (
selectItem) and a checkbox (checkbox).Add the form fields to your HTML template:
In this example, we are using the
ng-selectcomponent for the dropdown. We have added validation messages to show when the dropdown or checkbox fields are invalid.Note:
itemsis an array of objects that containidandnameproperties. This array is used to populate the dropdown options.In this example, we are adding a red border color to invalid fields and displaying the validation messages below the fields.
Add the necessary imports to your module: