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

Custom validation not being passed a field

3 Answers 235 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Troy
Top achievements
Rank 1
Troy asked on 20 Mar 2017, 03:45 AM
function myValidatorFunc(input) {
    console.log("VFunc: ", input);
    return true;
};
... [model definition] ...
complexField: {type:"object",
  validation: {myValidator: function(input) {
    console.log("Input length: " + input.length)
    return myValidatorFunc(input);
  }
}

I've got something like this in a grid with a custom edit template that lays out various fields.  "complexField" is an array of objects, and while I'm not using fields nested inside that as actual grid columns, the custom editor seems able to bind to them.  So the editor template might have among other fields, something like :

<input  data-role="numerictextbox" data-bind="value:complexField[0].intSubField1">

This seems to work, the binding displays and modifies "intSubField1" in element 0 of the data records "complexField" field.  And the  "myValidatorFunc()" function gets called for each field of the template, as expected.  However, for certain fields, the "input" parameter (which is a jquery element) has length 0, instead of 1 (or greater?) - the input element that has just been tabbed out of is not being passed.  So my "intSubField1" example might get passed to the validator, but for "intSubfield2" (done the same way), the valididator gets a 0-length "input" element, and I have nothing to access to do the validation.

Is there any legitimate case where a validator would get passed a zero-length "input" parameter?  Could this happen if, say, there was a basic HTML5 validator like "required" set?  This isn't the case here, and I would think the custom validator would just not get fired if basic validation failed first.  Firing the validator with no input element to validate seems more like a bug, or lack of support for these sorts of complex bindings.

I'm trying to create an example on the dojo, but so far I can't get it to fail in a similar fashion - I'm going to keep trying to figure out what in our actual code I might not have translated to the simplistic example.  We're getting this with 2016R3 and 2017R1SP1.  

3 Answers, 1 is accepted

Sort by
0
Troy
Top achievements
Rank 1
answered on 20 Mar 2017, 03:39 PM

This is the dojo example I'm trying to get to demonstrate the problem, but so far I haven't been able to recreate the 0-length input array being passed to the validator.  I'll update the URL if I can break it in later versions.

0
Troy
Top achievements
Rank 1
answered on 21 Mar 2017, 06:21 PM

I think I may have found the problem.  I've updated the dojo example with a simplified template.  We were using a kendo templating expression to index the complexChild array in the data record:

data-bind="value:complexChild[ #=0# ].estimatedWorkerHours"

Notice the whitespace before and after the expression "#=0#" (which is a simplistic 'element 0' for this example), which fails to pass the input element to validation.  If the whitespace is removed, validation gets the input element as expected.

data-bind="value:complexChild[#=1#].estimatedWorkerHours"

The binding itself seems to work properly in both cases, so there must be some different sort of parsing or selecting happening at validation time that doesn't like the whitespace.  This case in itself may be a bit obscure, but whatever kendo code underlies it may be more widely used and worth fixing.

0
Konstantin Dikov
Telerik team
answered on 22 Mar 2017, 07:08 AM
Hello Troy,

Although that the syntax with the additional space is valid for accessing array item, with the current implementation you should remove the white spaces in order to get everything to work correctly. On a side note, you could log this as an issue in our public repository:

Best 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
Troy
Top achievements
Rank 1
Answers by
Troy
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or