BoldSign®Effortlessly integrate e-signatures into your app with the BoldSign® API. Create a sandbox account!
Hi,
I have created the child component with the textbox, but the validation inside the component does not work. Some time ago you anwered this question where you have move the ValidationMessage outside of component, but this solution doesn't work as I expected. The main issues are:
My sample application included.
@using System.Linq.Expressions;
<SfTextBox @ref="textbox" Value="@Value" ValueChanged="ValueChanged" Input="@InputHandler" ValueExpression="@ValueExpression" FloatLabelType="@FloatLabelType.Always" Placeholder="Enter your name"></SfTextBox>
@code
{
SfTextBox textbox { get; set; }
private string _value { get; set; }
[Parameter]
public string ID { get; set; }
[Parameter]
public Expression<Func<string>> ValueExpression { get; set; }
[Parameter]
public string Value
{
get => _value;
set
{
if (!EqualityComparer<string>.Default.Equals(value, _value))
{
_value = value;
ValueChanged.InvokeAsync(value);
}
}
}
[Parameter]
public EventCallback<string> ValueChanged { get; set; }
[Parameter]
public EventCallback<InputEventArgs> InputHandler { get; set; }
} |
[Index.razor]
<div class="content wrapper">
<EditForm Model="@annotation">
<DataAnnotationsValidator />
<div class="textbox">
<label for="Name" style="padding: 20px 0 5px 0">Name (min 3):</label>
<SfTextBox id='textbox' @bind-Value="@annotation.Name" Placeholder="Enter a Name"></SfTextBox>
<ValidationMessage For="@(() => annotation.Name)" />
</div>
<div class="textbox">
<label for="Name custom" style="padding: 20px 0 5px 0">Name custom (min 3):</label>
<CustomTextbox @bind-Value="@annotation.NameCustom" />
<ValidationMessage For="@(() => annotation.NameCustom)" />
</div>
<div class="sfButton">
<SfButton type="submit" IsPrimary="true">Submit</SfButton>
</div>
</EditForm>
</div> |
<link rel='nofollow' href="_content/Syncfusion.Blazor.Themes/bootstrap4.css" rel="stylesheet" /> |
Hi,
thank you very much for provided example, it's working as I need.
It's possible to apply similar code for SfDropDownList? I tried it, but with no luck.
@using System.Linq.Expressions;
@typeparam TVal;
@typeparam TItemss;
<SfDropDownList Value="@Value" ValueChanged="ValueChanged" @oninput="@InputHandler" ValueExpression="@ValueExpression" TValue="TVal" TItem="TItemss" ShowClearButton="true" Placeholder="e.g. Australia" DataSource="@Country">
<DropDownListFieldSettings Text="Name" Value="Code"></DropDownListFieldSettings>
</SfDropDownList>
@code
{
[Parameter]
public List<TItemss> Country { get; set; }
SfTextBox textbox { get; set; }
private TVal _value { get; set; }
[Parameter]
public string ID { get; set; }
[Parameter]
public Expression<Func<TVal>> ValueExpression { get; set; }
[Parameter]
public TVal Value
{
get => _value;
set
{
if (!EqualityComparer<TVal>.Default.Equals(value, _value))
{
_value = value;
ValueChanged.InvokeAsync(value);
}
}
}
[Parameter]
public EventCallback<TVal> ValueChanged { get; set; }
[Parameter]
public EventCallback<ChangeEventArgs> InputHandler { get; set; }
} |
<CustomTextbox TVal="string" TItemss="Countries" Country="@Country" @bind-Value="@annotation.NameCustom">
</CustomTextbox>
<ValidationMessage For="@(() => annotation.NameCustom)" /> |
Hi Berly,
I appreciate your provided examples to this problem. I tried implementing this on a Syncfusion Blazor ComboBox, but it seems to not carry over the invalid validation to the child component to highlight the combobox red, though the validation message does appear below it. Was this changed in a recent update, or is there another solution necessary to carry EditForm validation into a custom child component containing a Syncfusion ComboBox component?
I can create a new thread if necessary, but I would be looking for a solution for this nonetheless.
Hi Alex Fornes,
Thank you for the update.
We have prepared a sample demonstrating how to achieve form validation for a child component using the ComboBox component. The validation is working correctly in the latest version, and the red border is properly applied when the value is null. For your reference, please find the sample and a video illustration of the behavior below.
To assist you further, could you kindly share the following:
Providing these details will help us better understand the problem and enable us to offer you a prompt and accurate response.
Please feel free to reach out if you have any additional questions or concerns.
Regards,
Priyanka K