DmitryEfimenko / TwitterBootstrapMvc

Fluent implementation of ASP.NET-MVC HTML helpers for Twitter Bootstrap.
Apache License 2.0
223 stars 79 forks source link

Replace "data-val-" on TextBoxFor not working #419

Closed speshulk926 closed 8 years ago

speshulk926 commented 8 years ago

What I am trying to achieve is to replace the default error message with a database driven error message. I created this same method to make all of my text, labels, static text, etc dynamic and it all works great. When I try to use the .Data() or .HtmlAttributes() it will not overwrite the data-val- objects. Model["validation.name.required"] translates to "Name is required." instead of "The Name field is required."

You can recreate it this way:

This works using standard TextBoxFor - Html.TextBoxFor(x => x.Name, new { data_val_required = Model["validation.name.required"], @class="form-control" }), Html.ValidationMessageFor(x => x.Name)

Output: <input name="Name" class="form-control" id="Name" type="text" value="" data-val-required="Name is required." data-val="true" data-val-length-max="50" data-val-length="The field Name must be a string with a maximum length of 50.">

This does not work - @:@form.FormGroup().TextBoxFor(x => x.Name).Data(new { val_required = Model["validation.Name.required"]}).Placeholder(Model["placeholder.Name"]).ShowValidationMessage(true).Label().LabelText(Model["label.Name"])

Nor does this - @:@form.FormGroup().TextBoxFor(x => x.Name).HtmlAttributes(new { data_val_required = Model["validation.Name.required"]}).Placeholder(Model["placeholder.Name"]).ShowValidationMessage(true).Label().LabelText(Model["label.Name"])

Output for both that do not work is the same: <input name="Name" class="form-control input-validation-error" id="Name" type="text" placeholder="Enter your name, please" value="" data-val-required="The Name field is required." data-val="true" data-val-length-max="50" data-val-length="The field Name must be a string with a maximum length of 50.">

DmitryEfimenko commented 8 years ago

This should be fixed. Please get latest and let me know if it worked fine for you.

speshulk926 commented 8 years ago

Works as expected now. Thanks for the insanely fast fix and update as usual! =D