Custom validator not working the way I expected

4 posts, 1 answers
  1. Andrew
    Andrew avatar
    12 posts
    Member since:
    Jan 2017

    Posted 26 Jan 2017 Link to this post

    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.

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 30 Jan 2017 Link to this post

    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.
  3. Andrew
    Andrew avatar
    12 posts
    Member since:
    Jan 2017

    Posted 31 Jan 2017 in reply to Konstantin Dikov Link to this post

    Hi Konstantin


    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

    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.

    (the 4th step will not occur)

    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.

  4. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 02 Feb 2017 Link to this post

    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.
Back to Top