Validators reset

Hi, I need to reset a data annotation validator for a SfTextBox (Inside Template, inside FormItem) after automatically populating it. The field has a "required" annotation and, if it's empty on submit, the validator will appear under the control saying that the value is required. The user can then click a SfFab button to automatically generate a value for this field, but in this case the validation error message remains, although the value is now non-empty. I suspect that revalidation happens on LostFocus event, but couldn't find the way to "simulate" it (BeginEdit/EndEdit, ...) I also don't want to revalidate the whole form, because, in case validation hasn't been done yet, it might show validation errors for other fields which would look odd.

Does anybody have any suggestion about it?

Thanks.


<FormValidator>
<DataAnnotationsValidator></DataAnnotationsValidator>
</FormValidator>
...
<FormItem Field="@nameof(Order.UniqueIdenty)" ColumnSpan="4">
<Template>
<div id="uniqueID" class="fab-grid-container custom-index">
<label id="labelUniqueID" class="e-form-label">Unique Identity</label>
<SfTextBox @bind-Value=Order.UniqueIdentity
TValue="string"
Placeholder="Enter Unique Identity">
</SfTextBox>
@if (Order.AddressId != 0 && string.IsNullOrEmpty(Order.UniqueIdentity))
{
<SfFab id="fab"
type="button"
Target="#uniqueID"
Position="FabPosition.BottomRight"
IconCss="fab-icons fab-icon-add"
title="Generate"
OnClick="GenerateUniqueIdentifier">

</SfFab>
}
</div>
</Template>
</FormItem>

1 Reply

YS Yohapuja Selvakumaran Syncfusion Team November 15, 2024 12:33 PM UTC

Hi P Grkovic,


Thank you for reaching out to us.


We have carefully reviewed the issue you reported and created a sample based on the code snippet you shared. After thorough validation, we found that the validation for the textbox is functioning as expected, and we were unable to replicate any unexpected behavior.


To assist you further, we have prepared a sample application that demonstrates the working functionality of the textbox validation. You can explore this sample and compare it with your implementation to ensure everything aligns as intended:


Sample: https://blazorplayground.syncfusion.com/rjLzWsCJfYWxKmBX


If you are still facing any issues or notice differences in behavior, we kindly request you to share more details about your specific use case or environment, such as:

  • The steps to replicate the issue.

  • Any customizations applied to the textbox or validation logic.

  • The version of the Syncfusion components and Blazor framework being used.

Providing this information will help us investigate further and offer a more tailored solution. Please feel free to reach out if you have additional questions or need further assistance.




Regards,

Yohapuja S



Loader.
Up arrow icon