Validator not firing after MVVM set

4 posts, 0 answers
  1. Eric
    Eric avatar
    3 posts
    Member since:
    Mar 2013

    Posted 15 Dec 2016 Link to this post

    When you update an MVVM model using the proper "set" method, any validators tied to controls tied to the model do not fire. I'm assuming it is because the validator is wired to the "blur" event of the textbox. I would prefer to not wire the validator to the "change" event, if possible.

    For example, I have a textbox that is required. If I blank out the value, the validator fires correctly. If there is some other action that changes the model, the validator does not re-execute and therefore remains.

    I've made a simple Dojo that represents this.Blank out the textbox, tab or click out, and then click the "Alter Model" button.

    http://dojo.telerik.com/oVEgE

  2. Ianko
    Admin
    Ianko avatar
    1711 posts

    Posted 19 Dec 2016 Link to this post

    Hello Eric,

    You can accomplish that by fully integrating the Kendo Validator to the MVVM model so that it validates on model's change. This is done by handling the change event of the Observable object and calling the validator's validate method. In this case you can disable the validateOnBlur option.

    Here you are a dojo example: http://dojo.telerik.com/oVEgE/2

    Regards,
    Ianko
    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. Eric
    Eric avatar
    3 posts
    Member since:
    Mar 2013

    Posted 20 Dec 2016 in reply to Ianko Link to this post

    Thanks. Is there a way to utilize the validateInput within the Change event so that the form isn't completely re-validating each time? I was looking at the argument object passed to the event as well as the kValidator object. I don't see a convenient way to backtrack to the appropriate validator(s). I know the model's field that was changed, but wouldn't know the controls associated with it in an automated fashion. I don't want a bunch of "if.then" or "switch" statements with custom logic.

    I tweaked the Dojo to look it up by name, but that seems messy and inconvenient to require all controls have the exact same name (or related convention) to the model.

    http://dojo.telerik.com/oVEgE/4

  4. Ianko
    Admin
    Ianko avatar
    1711 posts

    Posted 22 Dec 2016 Link to this post

    Hello Eric,

    The logic implemented there is accurate and it is sufficient enough to accomplish validating only single inputs instead of the entire form. 

    If the name, however, is different any automation would fail. In such case you should have some sort of mapping to ensure that each field change validates the mapped inputs. Here you are a very basic example for such a mapping: http://dojo.telerik.com/oVEgE/6

    Regards,
    Ianko
    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