Compare Validator Update

I have a doubt regarding compare validator. If I make correction in the first control the compare validator message remains till submit button is clicked.
BGGKYjISgt
But the submit is a success. Can we update the validator if any of the compared values change.
Please advise.

You need update the EditorContext to refresh validation. It is shown in other threads.

Im having the same issue and the EditContext.Validate() isn't working on change. Not sure if I have something wrong

@code {

	async Task OpenProjectDialog(SmtProjectDetailsModel data)
	{
		var result = await DialogService.OpenAsync("Project - Edit", ds =>
	@<RadzenTemplateForm @ref="@projectEditForm" Context="contextForm" Submit="@(args => OnSubmitProject())" TItem="SmtProjectModel" Data="@projectModel">
		<div class="container-fluid">

			<div class="row mb-2">
				<div class="col">
					<RadzenFormField Text="Start Date" Component="ProjectStartWindow" class="required-field-indicator">
						<RadzenDatePicker Name="ProjectStartWindow" @bind-Value="@projectModel.StartWindow" AllowClear="true" Change="RefreshProjectValidation" />
					</RadzenFormField>
					<RadzenRequiredValidator Component="ProjectStartWindow" Text="This field is required" Popup="false" />
					<RadzenCompareValidator Operator="CompareOperator.LessThan" Value="@projectModel.EndWindow" Component="ProjectStartWindow" Text="Start date can't be greater than end date." />
				</div>
			</div>
			<div class="row mb-2">
				<div class="col">
					<RadzenFormField Text="End Date" Component="ProjectEndWindow" class="required-field-indicator">
						<RadzenDatePicker Name="ProjectEndWindow" @bind-Value="@projectModel.EndWindow" AllowClear="true" Change="RefreshProjectValidation" />
					</RadzenFormField>
					<RadzenRequiredValidator Component="ProjectEndWindow" Text="This field is required" Popup="false" />
					<RadzenCompareValidator Operator="CompareOperator.GreaterThan" Value="@projectModel.StartWindow" Component="ProjectEndWindow" Text="End date can't be less than start date." />
				</div>
			</div>

			<div class="row mb-2">
				<div class="col">
					<RadzenButton ButtonType="ButtonType.Submit" Text="Submit" Icon="done" ButtonStyle="ButtonStyle.Primary" Style="min-width:90px" /> &nbsp; <RadzenButton ButtonType="ButtonType.Reset" Text="Cancel" Icon="close" ButtonStyle="ButtonStyle.Secondary" Click="@OnCancelDialog" Style="min-width:90px" />
				</div>
			</div>

		</div>
	</RadzenTemplateForm>
	, new DialogOptions() { Resizable = true, Draggable = true });
	}

	private RadzenTemplateForm<SmtProjectModel> projectEditForm;

	private void RefreshProjectValidation()
	{
		projectEditForm.EditContext.Validate();
	}

}

I am trying to compare two dates, start and end. When change a date, it needs to validate against the other so that start dates are prior to end dates and end dates can only be after start.

As is, the validation doesn't "refresh" on change. Once one of the fields gets changed and becomes invalid, unable to get it back to valid state. If change both fields, then they both stay invalid. It's as if the compare doesn't pickup new values.

image

I don't think this would work in an inline dialog. Try defining the dialog in its own .razor file.

Its definitely heading in the right direction, thanks. Unfortunately the error text still displays until I hit the submit button. But it at least allows me to submit now which is better than when I had inline.

Thoughts why my refresh validation (projectEditForm.EditContext.Validate()) doesnt remove the error text?

This shouldn't be required in your case to begin with. Can you reproduce this error in our online demo somehow?