vtfuture / BForms

Bootstrap Forms for ASP.NET MVC
MIT License
62 stars 33 forks source link

Custom validation on BsDateTime field #270

Closed ewelinaprus closed 8 years ago

ewelinaprus commented 8 years ago

Hello, I use custom validation on many fields in my model, but usually with string and some numeric types. Now I want to use them on BsDateTime field or another Bs* field, but I found some error:

"Validation type names in unobtrusive client validation rules must be unique.".

How cant I fix it?

With my best, Ewelina

ewelinaprus commented 8 years ago

I found some solution with yield break on TextValue property, but I have found further problems too... My ModelState.GetErrors() returns error for field new_date, but on my partial view there are new_date.TextValue and new_date.DateValue only. I guess that is some problem with binding error to field because of names (new_date and new_date.TextValue).

mariuscosareanu commented 8 years ago

Hi, You can use the second argument of the ValidationResult constructor, e.g:

return new ValidationResult(Resx.ErrorMessage, new List<string> { "TextValue" });
ewelinaprus commented 8 years ago

It works! Thanks a lot! :)