Base solution for your next web application
Open Closed

Best way to add required field validation #9574


User avatar
0
optixdev created

Angular 8 + .Net Core (ASPZero Version 8.7)

How to add required field validation

  • Adding required feild validator cusotm code for specific TextBox, CheckBox and Dropdownlist.
  • Adding required feild validator using Power tools.

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @optixdev,

    1. You can check one of the existing pages to see how we use required field validation. You can take a look at role creation modal.
    2. Power Tools allows you to select a property named required when you are defining a field. So, it is very easy.
  • User Avatar
    0
    optixdev created

    <input id="RoleDisplayName" #roleNameInput="ngModel" class="form-control" type="text" name="DisplayName" [(ngModel)]="role.displayName" required maxlength="64">

    <validation-messages [formCtrl]="roleNameInput"></validation-messages>

    So, we have to use only "#roleNameInput="ngModel"" in <validation-messages [formCtrl]="roleNameInput"></validation-messages> ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Yes, in that way, validation-message directive will display error message properly.

  • User Avatar
    0
    optixdev created

    Hi Ismail

    how to add required field validator for <p-editor> ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    I hven't tried this but it seems like there is an open issue on PrimeNG's GitHub repository, see https://github.com/primefaces/primeng/issues/3308. If it doesn't work, you can check the value in TypeScript code and display a message accordingly.