Hello Community,
My project is using ASP.NET Core validation in my model, but I'm not seeing any validation for my masked text box. All other inputs show a validation error message when necessary but those messages are missing the proper 'input name' within the error message.
I created a test project in which i attempted to recreate the issue, however to my surprise the maskedtextbox worked correctly. The other validation messages also were corrected.
Seems there is a conflict somewhere, but I can't for the life of me figure it out.
I've included the html output where you can see there are different HTML attributes being output.
I've also include my _Layout.cshtml and Create.cshtml. If there is anything else please let me know.
Thank you.
Hello Christo,
Thanks for your reply. Server side validation is what I'm trying to get working.
I've provided a sample of the issue I'm facing.
public string PhoneNumber { get; set; } |
<ejs-maskedtextbox id="PhoneNumber" ejs-for="PhoneNumber" mask="000-000-0000" change="validate" name="PhoneNumber">
</ejs-maskedtextbox> |
// checks the length of mask value and returns corresponding boolean value
var customFn = function(args) {
var argsLength = args.element.ej2_instances[0].value.length;
if(argsLength != 0){
return argsLength >= 10;
} else {
return true;
}
}
//value is returned based on the length of mask
var custom = function(args) {
var argsLength = args.element.ej2_instances[0].value.length;
if(argsLength == 0){
return 0;
} else {
return argsLength;
}
};
// sets required property in the FormValidator rules collection
var options = {
rules: {
'PhoneNumber': { numberValue: [customFn, 'Enter valid mobile number'] },
},
}
// defines FormValidator to validate the MaskedTextBox
var formObject = new ej.inputs.FormValidator('#customerForm', options);
//FormValidator rule is added for empty MaskedTextBox
formObject.addRules('PhoneNumber', { maxLength: [custom, 'Enter mobile number'] });
// places error label outside the MaskedTextBox using the customPlacement event of FormValidator
formObject.customPlacement = function(element, error) {
document.querySelector(".form-group").appendChild(error);
};
function validate() {
formObject.validate('PhoneNumber');
} |
Christo,
I understand that I could use the client side FormValidator. However, there must be some other conflict/issue effecting my project. Server side should work, I'm only validating on submit.
If I can take the affected code and place it in a new project and it works (same as the sample you sent), It should work in my existing project! Please help!