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

Kendo Grid - Data Annotations Validations

7 Answers 233 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Omar
Top achievements
Rank 1
Omar asked on 03 Sep 2013, 12:34 PM
I am working on a UI where I am editing grid in an Ajax Popup Edit. The following data annotations do not work as expected in the popup edit:

 [DataType(DataType.Password)]
        [Display(Name = "Confirm password")]
        [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
        public string ConfirmPassword { get; set; }

        [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
        [DataType(DataType.Password)]
        [Display(Name = "Password")]
        public string Password { get; set; }

        [StringLength(500, ErrorMessage = "Image path cannot be more than 500 characters.")]
        [Display(Name = "Image path")]
        [DataType(DataType.ImageUrl)]
        [RegularExpression(@"^http(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?$", ErrorMessage = "Image path format is incorrect.")]
        public string ImagePath { get; set; }

Currently for Add/Edit both, I am getting a minimum password length should be 6. Also both for Add and Edit I get "Image path format is incorrect" even when there is nothing typed in that field

In addition to the above
On Edit - I do not want the password to be required. On New I want password to be required.

Thanks

7 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 05 Sep 2013, 11:34 AM
Hi,

I am not sure if I understand correctly the issue with the length validation. Six seems to be used for the attribute MinLength value. Could you clarify a bit?
 I reproduced the problem with the regular expression validation and we will fix it for one of the next internal builds. A workaround for now is to override the mvcregex rule:

(function ($, kendo) {
    $.extend(true, kendo.ui.validator, {
        rules: { // custom rules
            mvcregex: function (input, params) {
                //check for the rule attribute
                if (input.filter("[data-val-regex]").length && input.val()) {
                    var regex = new RegExp(input.attr("data-val-regex-pattern"));
                    return regex.test(input.val());
                }
                return true;
            }
        }
    });
})(jQuery, kendo);
Using conditional validation based on the mode is not supported by the Validator. You should implement a custom attribute with a client side rule that gets the model for the row in edit mode and checks if it is new. Another option would be to remove the data-val-required attribute from the input in the Grid edit event:
function onEdit(e) {
    if (!e.model.isNew()) {
        $("#Password").removeAttr("data-val-required");
    }
}
but note that the server validation will still be triggered in the updated action in this case.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Omar
Top achievements
Rank 1
answered on 05 Sep 2013, 12:21 PM
Note from the validator for password that the password is not required (on either add or edit).

But if the code below is used in an Ajax poupedit, and when tried to submit, I get a minimum password length 6 message which I really should not if the field is left empty.

Regards
0
Daniel
Telerik team
answered on 09 Sep 2013, 08:09 AM
Hello again,

Thank you for clarifying. I reproduced this problem as well and we will fix it. As a small sign of gratitude for bringing these problems to our attention, I also updated your Telerik points.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Anurag
Top achievements
Rank 1
answered on 11 Nov 2013, 11:50 PM
Hi - I created a custom Regex validation and using it as a Data Annotation in our entity but it does not work through Kendo Popup Edit. Is it related to the problem above? Should we be using an alternate solution?

0
Daniel
Telerik team
answered on 13 Nov 2013, 11:42 AM
Hello,

Is the attribute using the same client-side attribute name? If not then you should extend the validator with a rule that handles inputs with the used attribute.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gentry
Top achievements
Rank 1
answered on 26 Feb 2014, 05:04 PM
Daniel....has this bug been fixed yet?
I'm still receiving similar errors...
0
Daniel
Telerik team
answered on 28 Feb 2014, 11:11 AM
Hello,

Which problem are you experiencing? The problem wit the not required fields should be fixed.


Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Omar
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Omar
Top achievements
Rank 1
Anurag
Top achievements
Rank 1
Gentry
Top achievements
Rank 1
Share this question
or