Datepicker and RequiredValidator issues

Hello,

I have been working on getting the validation working on a RadzenTemplateForm which has a couple of RazdenSteps.

one of my steps populates form fields dynamically and uses the name of the field as the value for name and component. I have run into a weird case where the validation for the date only works when the value is "test". I am doing some funky logic to get the date formatted back as a string on Change.

I am unsure if I have formatted something wrong, or I have come across a bug in the component. Code which works is pasted below, followed by the code that doesnt work.

Wanted to add, it only works with the string "test" io tried hardcoding a couple other strings, and only "test" worked.

Hi @Conner_Wulf

Welcome to the community.

Initially, could you check out Radzen Forum FAQ, particularly Item 4 with regards code formatting. It just makes it more readable and the code can be copied / pasted e.t.c. for working with.

Additional to this, can you recreate this error in one of the demo screens on the Radzen Components Demo site and post the code here. Would really aid in working towards a solution.

Many regards

Paul

Hey @Paul_Ruston Thanks for the reply, below is my formatted code. I am working on replicating the issue with the online code demos.
The first code block works with the work Test hardcoded as the Name/Component value, with the dynamic one not working. One extra detail is if I hardcode the value as "MyTestComponent" it doesnt work. It only works when the value is 'Test'

<RadzenFormField Text=@field.Name>
    <RadzenDatePicker Value="@(DateTime.TryParse(field.Value, out var dt) ? dt : (DateTime?)null)" TValue="DateTime?" Change="@((args) => field.Value = args != null ? args.Value.ToString("MM/dd/yyyy") : null)" DateFormat="MM/dd/yyyy" Name="test" />                                                 
</RadzenFormField>                                                 
<RadzenCustomValidator Component="test" Validator="@(() => DateTime.TryParse(field.Value, out var dt))"  Text="Please Select a Date" Popup=false style="margin-left:15px" />
 <RadzenFormField Text=@field.Name>                                                    
    <RadzenDatePicker Value="@(DateTime.TryParse(field.Value, out var dt) ? dt : (DateTime?)null)"  TValue="DateTime?" Change="@((args) => field.Value = args != null ? args.Value.ToString("MM/dd/yyyy") : null)" DateFormat="MM/dd/yyyy" Name=@field.Name />                                                 
</RadzenFormField> 
<RadzenCustomValidator Component=@field.Name Validator="@(() => DateTime.TryParse(field.Value, out var dt))"  Text="Please Select a Date" Popup=false style="margin-left:15px" />

Update after using the online demo. I was unable to get the custom validator to work with any variation of the code I posted

@using Radzen
@using System.Text.Json

<RadzenStack class="rz-p-0 rz-p-md-12">
  

    <RadzenTemplateForm TItem="Model" Data=@model Submit=@OnSubmit InvalidSubmit=@OnInvalidSubmit>
      <RadzenFormField Text=@model.Name>
    <RadzenDatePicker Value="@(DateTime.TryParse(model.Value, out var dt) ? dt : (DateTime?)null)" TValue="DateTime?" Change="@((args) => model.Value = args != null ? args.Value.ToString("MM/dd/yyyy") : null)" DateFormat="MM/dd/yyyy" Name="test" />                                                 
</RadzenFormField>                                                 
<RadzenCustomValidator Component="test" Validator="@(() => DateTime.TryParse(model.Value, out var dt))"  Text="Please Select a Date" Popup=false style="margin-left:15px" />
<RadzenButton Text="Submit Application" ButtonType="ButtonType.Submit" />
    </RadzenTemplateForm>

    <EventConsole @ref=@console />
</RadzenStack>

@code {
        class Model
        {
            public string Name { get; set; }
            public string Value { get; set; }
        }

    

    Model model = new Model{
        Name = "Start Date"
    };
    EventConsole console;

    void OnSubmit(Model model)
    {
        console.Log($"Submit: {JsonSerializer.Serialize(model, new JsonSerializerOptions() {  WriteIndented = true })}");
    }

    void OnInvalidSubmit(FormInvalidSubmitEventArgs args)
    {
        console.Log($"InvalidSubmit: {JsonSerializer.Serialize(args, new JsonSerializerOptions() {  WriteIndented = true })}");
    }
}

Validation relies on @bind-Value. If you don't want to use it you should set ValueExpression manually. More info here: CustomValidator - #2 by korchev