TwitterBootstrapMvc
TwitterBootstrapMvc copied to clipboard
Validation
It appears that the plugin is not getting the full property name when determining whether or not to show validation.
For example, a property with a name of ClaimNumber in the root of the model that also exists within a collection property. If either is required and at least one of the required properties is not filled in, they will both appear as a validation error on the UI.
public class Example
{
[Required]
public string ClaimNumber {get;set;} // gets an appropriate validation error.
public Claim SubmittedClaim {get;set;}
public Claim
{
public string ClaimNumber {get;set;} // gets an inappropriate validation error.
}
}
When I inspect the UI, I can see that both the ClaimNumber and the Claim.ClaimNumber elements have received validation errors. It seems like the validation is ignoring the prefix of the property name.
could you please try the same scenario without BMVC and see if you get the same result?
When removing BMVC, the error does not occur.
I cannot reproduce the behaviour that you are describing. Here is what I have in the view:
@using (var f = Html.Bootstrap().Begin(new Form().Type(FormType.Horizontal)))
{
@f.FormGroup().TextBoxFor(x => x.ClaimNumber)
@f.FormGroup().TextBoxFor(x => x.SubmittedClaim.ClaimNumber)
@Html.Bootstrap().SubmitButton()
}
What do you have?
Thanks for your response. Here's what we have:
@using (var f = Html.Bootstrap().Begin(new Form("CreateAuthorizationRequest").Class("order-form").Type(FormType.Horizontal).LabelWidthMd(4).InputWidthMd(8)))
{
@f.FormGroup().Class("date").TextBoxFor(x => x.DateOfLoss).Format("{0:d}").Class("date-mask").AppendIcon("fa fa-calendar").WidthMd(5)
@Html.EditorFor(x => x.locationInfo)
}
Then, within our "locationInfo" partial, we have the following:
var f = Html.Bootstrap().Misc().GetBuilderFor(new Form().Type(FormType.Horizontal).InputWidthMd(9).LabelWidthMd(3));
...
@f.FormGroup().Class("date").TextBoxFor(x => x.DateOfLoss).Format("{0:d}").Class("date-mask").AppendIcon("fa fa-calendar").WidthMd(4)
Inspecting the DateOfLoss controls in chrome produces the following ids:
First one (Required): DateOfLoss
Second one (in partial, not required): LocationInfo_d5c9e859-9418-40a9-98ba-a6a2632313e2__DateOfLoss
When submitting with no input, I get the following results (note that the asterisks represent that the property is required by the model):
First (required):
Second (in partial, not required):
When I enter a value for the first DateOfLoss value (the required one) I get the following results:
First (required):
Second (in partial, not required):
I believe the actual issue is found in: https://github.com/DmitryEfimenko/TwitterBootstrapMvc/blob/53a6f9c40a6d90d5797d98dddf082764ad2b65c0/TwitterBootstrapMVC/Renderers/Renderer.ControlGroup.TextBox.cs line 21. It looks like the htmlFieldName is just the field name without prefix. Causing ClaimNumber to match SubmittedClaims.ClaimNumber because it doesn't see the prefix.
The confusing part was it looks like it does validate correctly because if your plugin doesn't catch it the built-in MVC stuff will style the field. We were able to verify this issue by making any other field in the collection in our root object trigger its [Required]on the property. The results would have the field showing as invalid but the difference would be that your plugin was not adding the "has-error" class to the control group but MVC was applying the "input-validation-error" class to the field. This would result in just the field being styled red instead of the field and label which the control group having "has-error" would do.
Also we are using the Bootstrap 3 version
Any updates on this? We are nearing a go live.
I still cannot reproduce the issue. Even when using EditorFor
. Could someone please send me a sample project showing the issue?
I have created a small project exemplifying the issue. How would you like me to deliver it to you?
Someone attempted to send it to me via email (found at the end of this page), but it didn't work for some reason - I just was not receiving the email. You can give it a try since it's easiest. Make sure to rename .zip
into something else because gmail might block .zip
file.
If that does not work we'll try to use some free file sharing service.
Thanks for the info, I have sent it with a ".piz" attachment extension.
quick status update. I've looked at it tonight. I copy/pasted the code from your test project into my own test project. It was a straight copy of Controller actions, Models, Views and the DynamicCollectionExtensions - and it just worked as expected. Still trying to find what's different... will look at it more tomorrow.
Hi Dmitry, just wanted to check in and see if anything has been done with this? We are going live with our product and would like to be able to eliminate this as an issue.
Thanks!
Hi, I looked at it some more, but unfortunately I can't report any good news yet. What version of VS do you use?
We are using 2012, but have also experienced the same behavior with 2013.