EditForm and error state

Hello,

Just a question, is TextBox is interfaced with EditForm so that error state is automatically set in case of error ?

Regards,

Brice.



4 Replies

PM Ponmani Murugaiyan Syncfusion Team June 1, 2020 10:07 AM UTC

Hi Brice, 
 
We have validated your reported query. We have prepared sample Textbox with EditForm based on your requirement. Please find the code snippet and test sample below for reference. 
 
[Index.razor] 
 
<EditForm EditContext="@_editContext"> 
    <DataAnnotationsValidator /> 
    <div class="col-md-12 maring15"> 
        <label for="Email">Email</label> 
        <SfTextBox ID="text" @bind-Value="@ModelValue.EmailAddress" Input="onInput" CssClass="@cssClass"></SfTextBox> 
        <ValidationMessage For="@(() => ModelValue.EmailAddress)" /> 
    </div> 
</EditForm> 
 
@code { 
 
    public string cssClass { get; set; } 
 
    private EditContext _editContext; 
 
    private MultiSelectModel ModelValue = new MultiSelectModel(); 
 
    protected override void OnInitialized() 
    { 
        _editContext = new EditContext(ModelValue); 
    } 
 
    private void onInput(InputEventArgs args) 
    { 
        this.ModelValue.EmailAddress = args.Value; 
        var isValid = _editContext.Validate(); 
        if (!isValid) 
        { 
            cssClass = "e-error"; 
        } 
        else 
        { 
            cssClass = "e-success"; 
        } 
        StateHasChanged(); 
    } 
} 
 
 
 
Kindly check with the above sample. Please get back us, if you need further assistances. 
 
Regards, 
Ponmani M 



BF Brice FROMENTIN June 2, 2020 12:14 PM UTC

Thanks for the sample, but I have lots of TextBox in my page, I prefer waiting that the component automatically apply right style automatically.


EK Edward Kagan June 2, 2020 01:44 PM UTC

I've been asking for this forever!!!  It's absolutely ridiculous to have to do it manually.  Look how Telerik components are working.  Every single input-type control triggers validation @onblur and automatically sets it's class to invalid if the input fails validation.  This is common and basic functionality,  Why in the world do I have to write a ton of ridiculous copy-paste extra code to accomplish this???


PM Ponmani Murugaiyan Syncfusion Team June 3, 2020 01:20 PM UTC

Hi All,  

We have considered this as feature request and this support will be include in Voulme2 release, which is expected to be rolled out on end of June 2020. You can track the status of the feature in the below link from our feedback portal.  


Regards, 
Ponmani M 


Loader.
Up arrow icon