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

Validator not firing after MVVM set

3 Answers 253 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 15 Dec 2016, 05:06 PM

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

3 Answers, 1 is accepted

Sort by
0
Ianko
Telerik team
answered on 19 Dec 2016, 06:41 AM

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.
0
Eric
Top achievements
Rank 1
answered on 20 Dec 2016, 05:09 PM

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

0
Ianko
Telerik team
answered on 22 Dec 2016, 06:23 AM

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.
Tags
Validation
Asked by
Eric
Top achievements
Rank 1
Answers by
Ianko
Telerik team
Eric
Top achievements
Rank 1
Share this question
or