This is a migrated thread and some comments may be shown as answers.

Custom validator not working the way I expected

3 Answers 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 26 Jan 2017, 03:26 PM

Hello,

I've a custom validator that is validating a custom popup editor template in a grid.

The problem I'm facing is that when I set a value in a NumericTextBoxFor() field and the validator fails (return false) then the value isn't written in the popup editor's model so when I write in the same field the value I had previously written the validator's message isn't hidden.

Example:

  1. I write "24" in the field. (the validator returns true and the model contains "24")
  2. I write "-1" in the field. (the validator returns false and the model still contains "24"). I think this is the problem, even when the validator returns false the model must be updated with "-1" but instead it ignores the new value so the model still contains "24". At this point the validator's message is shown.
  3. I write again "24" in the field. (the validator returns true but the model already contained "24") so the validator's message isn't hidden even when "24" is a valid value
  4. I write another value valid for the validator. (the validator returns true and the model contains the new value). At this point the validator's message is hidden.

How can I solve this problem?

Thank you.

3 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 30 Jan 2017, 12:52 PM
Hi Andrew,

I have to say that the behavior that you are describing is made that way by design and the original (valid) value will be the value in the model and since no change will occur if you enter the same value again, no validation will fire afterwords (the 4th step will not occur).

Currently, the only thing that I can suggest is to log this as a feature request in our public portal:

Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Andrew
Top achievements
Rank 1
answered on 31 Jan 2017, 01:24 PM

Hi Konstantin

[quote]
I have to say that the behavior that you are describing is made that way by design and the original (valid) value will be the value in the model

[/quote]

Then why the value typed by the user is accepted in the widget when the validation fail? In that way I've an inconsistency, I mean, I've some value in the view (the widget) and a different value in the model.

[quote](the 4th step will not occur)[/quote]

In fact the sequence of steps I wrote in the question is actually what is happening when I run the app so the 4th step is always happening.

Thank you for your time.

0
Accepted
Konstantin Dikov
Telerik team
answered on 02 Feb 2017, 09:29 AM
Hi Andrew,

Regarding the first point, I understand how this might seem inconsistent, but this is how the model validation works.

As for the other part, I meant the 3rd step and not the 4th (where the previously valid value is entered again after the failed validation). At this point, no validation will fire and that is why the validation message will not be hidden. Notwithstanding, you can log a feature request in our portal by describing the behavior that you are expecting from the model validation.


Regards,
Konstantin Dikov
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Andrew
Top achievements
Rank 1
Share this question
or