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
[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
0
Hi,
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:
but note that the server validation will still be triggered in the updated action in this case.
Regards,
Daniel
Telerik
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);
function
onEdit(e) {
if
(!e.model.isNew()) {
$(
"#Password"
).removeAttr(
"data-val-required"
);
}
}
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
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
Hello again,
Daniel
Telerik
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
Hello,
Daniel
Telerik
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...
I'm still receiving similar errors...
0
Hello,
Which problem are you experiencing? The problem wit the not required fields should be fixed.
Regards,
Daniel
Telerik
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!