DmitryEfimenko / TwitterBootstrapMvc

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

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

Closed speshulk926 closed 7 years ago

speshulk926 commented 7 years ago

I put in an issue about a year ago here and I seem to be having issues making it work again. I wanted to make sure that something didn't get stepped on with another update? I tried something very similar to what I posted and it doesn't seem to work anymore. I made a helper SiteResourceText and SiteResourceHtml which returns string and MvcHtmlString, respectively, that gets text from a database to replace with what is there.

In the database, I have changed the required text to "First Name is so required" where as the default text is "First Name is required".

Does not work:

Html.Bootstrap().Div(
    Html.Bootstrap().TextBoxFor(x => x.FirstName)
    .ShowValidationMessage(false)
    .Class("filter-name")
    .HtmlAttributes(new
    {
        maxlength = 15,
        data_val_required = Html.SiteResourceHtml("validation.firstname.required", ownerModel),
        data_val_length = Html.SiteResourceHtml("validation.firstname.length", ownerModel),
        data_val_regexwithoptions = Html.SiteResourceHtml("validation.firstname.invalid", ownerModel)
    })
    .Label()
    .ShowRequiredStar(true)
).Class("form-group").Sm(3).Md(4),

image


Works:

Html.Bootstrap().Div(
    Html.LabelFor(x => x.FirstName, "First Name", new {@class="control-label"}),
    Html.TextBoxFor(x => x.FirstName, new {
        maxlength = CS.MSCustomerAccess.Business.Models.FieldLengths.FirstNameMax,
        data_val_required = Html.SiteResourceHtml("validation.firstname.required", ownerModel),
        data_val_length = Html.SiteResourceHtml("validation.firstname.length", ownerModel),
        data_val_regexwithoptions = Html.SiteResourceHtml("validation.firstname.valid", ownerModel),
        @class = "form-control"
    })            
).Class("form-group").Sm(3)

image

DmitryEfimenko commented 7 years ago

I have tested with this code:

@Html.Bootstrap().Div(
    Html.Bootstrap().TextBoxFor(x => x.MyFirstNameIs)
    .ShowValidationMessage(false)
    .Class("filter-name")
    .HtmlAttributes(new
    {
        maxlength = 15,
        data_val_required = "custom required val"
    })
    .Label()
    .ShowRequiredStar(true)
).Class("form-group").Sm(3).Md(4)

Inspecting generated html showed attribute: data-val-required="custom required val". Seems to be working as expected. Could you see the generated output of your example?

speshulk926 commented 7 years ago

Man, really sorry. You are right. I had an old version and thought I updated it, but didn't update it for the Website, only the Business layer (which I am not sure why it was even referenced). It is still working. Sorry again!

DmitryEfimenko commented 7 years ago

no problem! Good luck!