Home > Enterprise >  How to Make a Validation Date Not Null on Blazorise
How to Make a Validation Date Not Null on Blazorise

Time:12-23

im working on blazor with Blazorise Modal Component and i can't validate an DateEdit, i try with @ValidationRule.IsNotEmpty and it didn't work

<Validation Validator="@ValidationRule.IsNotEmpty">
     <Field>
           <FieldLabel>Date</FieldLabel>
           <DateEdit TValue="DateTime?" Placeholder="Select Date" @bind-Date="@input.date"></DateEdit>
     </Field>
 </Validation>

Any suggestion?

CodePudding user response:

i have a similar issue and solve it with a custom validation, try this:

<Validation Validator="@ValidateDate">
 <Field>
       <FieldLabel>Date</FieldLabel>
       <DateEdit TValue="DateTime?" Placeholder="Select Date" @bind-Date="@input.date"></DateEdit>
 </Field>
</Validation>

And then in the blazor page:

@code{
void ValidateDate( ValidatorEventArgs e )
{
    if(e.Value != null)
    {
        e.Status = ValidationStatus.Success;   
    }else{
        e.Status = ValidationStatus.Error; 
    }
}
}
  • Related