Telerik Forums
UI for Blazor Forum
1 answer
93 views

Hi,

 

I have a TelerikForm containing a Fluent Validator and 2 buttons.
Only one of them has to validate the form.

However, even if I set NO  code into the button's associated method, it does trigger the validation.

Seems to be a default behaviour.

How to disable it for my second button?

 

Thx in advance

 

A

Radko
Telerik team
 answered on 25 Dec 2023
1 answer
789 views

Hi

 

After our update to .Net 7, FluentValidation does not work with complex models anymore.

We're using FluentValidation 11.5.1 (latest)

Blazored.FluentValidation 2.1.0 (latest)

I get the error message: Cannot validate instance of type "The Composed Class Type ". Can only validate Instance of Type "Parent Class".

 

Has somebody a solution for this issue?

It worked fine in the previous version.

 

Thank you.

 

Nicolas
Top achievements
Rank 1
Iron
 answered on 16 Mar 2023
1 answer
83 views

I have a question regarding the TelerikValidationMessage, which is showing in one form, but not in another. I am using data annotations on the properties of the User class. 

public class User
{
    [Display(Name = "Voornaam*")]
    [Required(ErrorMessage = "Voornaam ontbreekt.")]
    [Placeholder(Description = "Voer de voornaam in.")]
    public string FirstName { get; set; }
...

The first form is a non-dynamic form with fields for every property in the User class. It is using a Model with bind-Value instead of an EditContext with Value and ValueChanged. When I press the Submit button, the validation summary is shows as are the validationmessages below the textinputs. This is the desired situation.

<TelerikForm Model="@TestUser"
                     OnValidSubmit="@HandleValidSubmit"
                     OnInvalidSubmit="@HandleInvalidSubmit">
            <FormValidation>
                <DataAnnotationsValidator></DataAnnotationsValidator>
            </FormValidation>
            <FormItems>
                
                <FormItem Field="@nameof(User.FirstName)">
                    <Template>
                        <div class="mb-3 row">
                            <label for="firstName" class="k-label k-form-label col-sm-2">Voornaam *</label>
                            <div class="col-sm-10">
                                <TelerikTextBox Id="firstName" @bind-Value="@TestUser.FirstName" InputMode="text" PlaceHolder="Voornaam"></TelerikTextBox>
                                <TelerikValidationMessage For="@(() => TestUser.FirstName)"></TelerikValidationMessage>
                            </div>
                        </div>
                    </Template>
                </FormItem>
...

Since I am trying to create a dynamic form which will work for all my classes, I have created a second form. This second form is a dynamic form using an EditContext.

<TelerikForm EditContext="@MyEditContext"
             OnValidSubmit="@HandleValidSubmit"
             OnInvalidSubmit="@HandleInvalidSubmit"
             ValidationMessageType="@FormValidationMessageType.Inline"
             >
    <FormValidation>
        <DataAnnotationsValidator></DataAnnotationsValidator>
        <ValidationSummary />
    </FormValidation>
    <FormItems>
        
        
        @foreach (var propertyInfo in DataContext.GetType().GetProperties())
        {
            <FormItem Field="@propertyInfo.Name">
                <Template>
                    <div class="mb-1 row">
                        <label for="@(propertyInfo.Name)" class="k-label k-form-label col-sm-2">@propertyInfo.DisplayName()</label>
                        <div class="col-sm-10">
                            <TelerikTextBox Id="@(propertyInfo.Name)"
                                            Value="@propertyInfo.GetValue(DataContext)?.ToString()"
                                            ValueExpression="@(() => propertyInfo.Name)"
                                            OnChange="OnChange"
                                            ValueChanged="@(value => OnValueChanged(value, propertyInfo.Name))"
                                            InputMode="text"
                                        PlaceHolder="@propertyInfo.PlaceholderDescription()">
                            </TelerikTextBox>
                            <TelerikValidationMessage For="@(() => propertyInfo.Name)"></TelerikValidationMessage>
                        </div>
                    </div>
                </Template>
            </FormItem>
        }
        
    </FormItems>
</TelerikForm>

And here's the imporant part of the code behind. This is proof of concept code and will be improved later.

protected void OnValueChanged(object e, string prop)
    {
        var propertyInfo = DataContext.GetType().GetProperty(prop);
        if (propertyInfo == null) return;

        if (propertyInfo.PropertyType == typeof(int))
        {
            var intValue = Convert.ToInt32(e);
            propertyInfo.SetValue(DataContext, intValue);
        }

        if (propertyInfo.PropertyType == typeof(string))
            propertyInfo.SetValue(DataContext, e.ToString());

        if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?))
            propertyInfo.SetValue(DataContext, DateTime.Now);

        if (propertyInfo.PropertyType == typeof(bool) || propertyInfo.PropertyType == typeof(bool))
            propertyInfo.SetValue(DataContext, true);
    }

    protected void OnChange(object e)
    {
        MyEditContext.Validate();
    }

When I press the submit button, the validationsummary is correctly shown, the labels color red and the border of the textinput colors red (after adding some css). So the validation seems to be working fine. However, the validationmessage below the textinput isn't showing. It isn't even in the DOM, so I assume it's not generated. I have searched the Interwebs and this forum/documentation, but I can't find the reason why the validationmessage isn't showing. Any help would be highly appreciated.

Btw; the second form shows the Inline messagetype, but that has no effect.

ValidationMessageType="@FormValidationMessageType.Inline"
Dimo
Telerik team
 updated answer on 01 Dec 2022
1 answer
61 views

Good Morning,

I vave this code. I try to create a FluentValdation in TelerikForm, code builts good.  When i submit empty form, validations are good(), but the form doesn't show the errors.


<TelerikForm Model="@TriggerDetail" Columns="1" ColumnSpacing="25px" OnValidSubmit="@HandleValidSubmit" EditContext="@EditContext">
    <FormValidation>
        <FluentValidationValidator Validator="@Validator"></FluentValidationValidator>
    </FormValidation>    
    <FormItems>
        <FormGroup LabelText="General Information" Columns="2" ColumnSpacing="15px">
            <FormItem Field="@nameof(TriggerDetailModel.Name)" LabelText="@Localizer["JobTrigger_Name"]" Enabled="@Enabled"></FormItem>
            <ValidationMessage For="@(() => TriggerDetail.Name)" />
            <FormItem Field="@nameof(TriggerDetailModel.Group)" LabelText="@Localizer["JobTrigger_Group"]" Enabled="@Enabled">
                <Template>
                    <label class="k-label k-form-label">@Localizer["JobTrigger_Group"]</label>
                    <TelerikAutoComplete Data="@ExistingTriggerGroups" @bind-Value="@TriggerDetail.Group" ClearButton="true" Enabled="@Enabled" />
                </Template>
            </FormItem>
			<ValidationMessage For="@(() => TriggerDetail.Group)" />
		</FormGroup>
	</FormItems>
	<FormButtons>       
            <TelerikButton Icon="caret-alt-to-left" OnClick="@BackStep" ThemeColor="@(ThemeConstants.Button.ThemeColor.Error)">@Localizer["Back"]</TelerikButton>
            <TelerikButton ButtonType="ButtonType.Submit" Icon="caret-alt-to-right" ThemeColor="@(ThemeConstants.Button.ThemeColor.Info)">@Localizer["Next"]</TelerikButton>        
    </FormButtons>
</TelerikForm>
	
	
@code{
	public TriggerDetailModel TriggerDetail { get; set; } = null!;
	public TriggerDetailValidator Validator { get; set; } = new();
	
    private void HandleValidSubmit()
    {
        var validationResult = Validator.Validate(TriggerDetail);
        if (validationResult.IsValid)
        {
            NextStep();
        }
        else
        {
            //Errores
        }            
    }
}

public class TriggerDetailValidator : AbstractValidator<TriggerDetailModel>
{                
        public TriggerDetailValidator()
        {           
            RuleFor(t => t.Name).NotEmpty();
            RuleFor(t => t.Group).NotEmpty();
        }
}

Where is the problem?

 

Thanks

Svetoslav Dimitrov
Telerik team
 answered on 18 Nov 2022
1 answer
69 views

Hi,

I would like to use a TelerikTooltip as validation message container, so that the user can click to close the tooltip after reading the message.

Can the TelerikTooltip be made to display immediately and then respond to clicks as normal afterwards?

 

Rob
Top achievements
Rank 1
Iron
Iron
 answered on 30 May 2022
1 answer
422 views
I am working on flow, where based on users selection in dropdown, I want to update the validations of TextBox field.
Is there any way to do that ?
Becz at start we are creating model and specifying all specific validations, but now how we can apply validations based on users selection.
1 answer
612 views

Hello I have a question related to Validation.

In our application we use forms that are dynamically rendered (without using a model). Therefor we are not able to use the TelerikFrom and its edit context. I was wondering if it is possible to do Validation on a single Property/field and show a validation message (with the Validation built by Telerik)? As far as I can see, you seem to only support validation for components wrapped in the TelerikForm/EditForm. Thanks in advance

Marin Bratanov
Telerik team
 answered on 15 Jan 2022
1 answer
864 views

I have a need to reset the form and it's validation back to a pristine state (blank form with validation) either when the form is complete and successful response is returned or by user initiated click event.

I don't see anywhere in the documentation to do so.

I have set it equal to a new instance of the FormModel, and that indeed clears the form, BUT it does not reset the form validation or any of those behaviors.

How can I reinitialize the form the same way that the form initializes on route activation?

 

Marin Bratanov
Telerik team
 answered on 16 Nov 2021
1 answer
88 views

When the component is intialized, I need the inputs to display with the red (invalid) classes and such.

The validation is in place as when I start to enter, then backspace back to empty it TURNS red, but I need it to be red by default when the form initializes.

How do I do this using <TerlerikForm>

Radko
Telerik team
 answered on 18 Oct 2021
Top users last month
Dominik
Top achievements
Rank 1
Giuliano
Top achievements
Rank 1
Dominic
Top achievements
Rank 1
Glendys
Top achievements
Rank 1
Iron
NoobMaster
Top achievements
Rank 2
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?