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

Validation rule

7 Answers 209 Views
General Disccussions
This is a migrated thread and some comments may be shown as answers.
Jan Kaare
Top achievements
Rank 2
Jan Kaare asked on 19 Apr 2013, 07:41 PM
For the grid PHP wrapper usage, how to set up a string pattern validation rule for string value XX:XX ie. resulting string 12:15 as an example?

And for the same grid PHP wrapper usage, how to set a grid string cell's maxlength, to let the cell input operate identical to what's found from standard html maxlength?

7 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 23 Apr 2013, 10:53 AM
Hello Jan,

Like the other type of validations, pattern should be set in the DataSource's schema. For example:
$productNameField = new \Kendo\Data\DataSourceSchemaModelField('ProductName');
$productNameField->type('string')
           ->validation(array('required' => true, 'pattern' => '< your pattern >'));

Regarding your second question, there is no text maxlenght validation rule among the default ones. If you would like to check the length of the user input, you may use a pattern or custom validation rule.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Jaymie
Top achievements
Rank 1
answered on 03 Jun 2013, 10:06 AM
Hi Alexander,

Would you be able to post an example of how to implement a custom validation rule using the PHP Wrapper. I have had several attempts at implementing one myself but can't get it to test against the rule.

Thanks in advance,
Jaymie
0
Alexander Valchev
Telerik team
answered on 05 Jun 2013, 09:09 AM
Hi Jaymie,

The tricky part is to use \Kendo\JavaScriptFunction in order to serialize the custom rule function properly.

Example 1:
$productNameField->type('string')
                 ->validation(array('required' => true, 'myCustomRule' => new \Kendo\JavaScriptFunction('myCustomRule')));
 
//where myCustomRule is a name of a JavaScript function

Example 2:
class customSchemaValidation extends \Kendo\Data\DataSourceSchemaModelFieldValidation {
    public function foo($value) {
        if (is_string($value)) {
            $value = new \Kendo\JavaScriptFunction($value);
        }
 
        return $this->setProperty('foo', $value);
    }
}
 
$unitPriceValidation = new customSchemaValidation();
$unitPriceValidation->required(true)
             ->foo('foo')
             ->min(1);
 
//where foo is the name of the custom rule function

I hope this information will help.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Raymond
Top achievements
Rank 1
answered on 16 Oct 2013, 04:37 PM
Can you please show an example of what the myCustomRule javascript function might look like in example 1 ?  

I'm using a popup template to edit some fields from a grid and want to validate the form when the Update button is clicked. 
I tried using this method on a single DataSource field, with none of the other fields (5 in total) set to be 'required'.  When I click the Update button, the javascript function is called and it appears that the entire popup window is passed as an argument.  In addition it seems that all 5 of my fields are validated, as an empty notification tooltip is generated for each.
0
Nikolay Rusev
Telerik team
answered on 21 Oct 2013, 08:11 AM
Hello Raymond,

Indeed the validation rule will be executed against all inputs in the form on `Update` button click. You will have to assert against that field and perform validation in the rule is for that field. Here few examples for this: 
 - Custom Rules
 - Custom Validation Rules Overview

It is exactly the same as in the above articles in the context of the Grid widget. Here is an example with custom validation rule for `ProductName` in Grid popup editing: http://jsbin.com/iVuZeRi/1/edit

Regarding the empty validation tooltip - you can define custom validation message per validation rule on the input element as data attribute. In the above example the validation rule is named "custom" and the ProductName input has data attribute data-custom-msg="some text" which is the validation message for that rule.
 
You can find more details on how validation messages works here: Defining Custom Messages.

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Raymond
Top achievements
Rank 1
answered on 21 Oct 2013, 02:12 PM
Thank you, that helps with the custom message, but does not help with the initial problem.

I want to be able to validate when I press the Update button.  A user might hit update without entering a field, thus never activating an onBlur, or I may have interdependent fields where I don't want to validate until I'm done.  The examples you kindly provided don't help because I'm using the popup template, the 'Update' button isn't part of my template form, it's part of the kendo window generated for the popup, so it doesn't trigger validation.
0
Nikolay Rusev
Telerik team
answered on 23 Oct 2013, 07:26 AM
Hello Raymond,

In such a case you should handle the click of that custom button, find the Kendo Validator which is initialized for the edit form and call its validate method. For example: http://jsbin.com/iNIqul/1/edit

Regards,
Nikolay Rusev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Disccussions
Asked by
Jan Kaare
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Jaymie
Top achievements
Rank 1
Raymond
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or