DmitryEfimenko / TwitterBootstrapMvc

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

VisibleDependsOn #200

Closed sgentile closed 10 years ago

sgentile commented 10 years ago

I'm having an issue where VisibleDepends on does not 'fire' when the page loads. After selecting, ie. a dropdown list or radiobutton list value, then it fires, but on load it isn't firing.

I am using TwitterBootstrapMvcJs-3.0.4.js

sgentile commented 10 years ago

It appears to work correctly if I make this change ?

$(selector).change();

            //if ($(selector).is(':radio')) {
            //    $(selector + ':checked').change();
            //} else {
            //    $(selector).change();
            //}
DmitryEfimenko commented 10 years ago

This was fixed in the latest release (yesterday). The Javascript file now comes from Nuget. Please let me know if you still experience issue.

sgentile commented 10 years ago

Looks good on radio/checkbox... it's not working on my dropdownlist/select though (works once it's changed, but on load it's not)

DmitryEfimenko commented 10 years ago

Please get latest. This should be fixed.

sgentile commented 10 years ago

I had to add this

$(document).on('change', selector + ':not(:checkbox)', function () {
                if ($(this).val().toString() == val.toString()) {
                    toHide.show(isFirstRun ? undefined : speed);
                } else {
                    toHide.hide(isFirstRun ? undefined : speed);
                }
            });

when I have the :not(:hidden) it didn't fire on load

sgentile commented 10 years ago

(not add, but replaced same line where it had hidden)

DmitryEfimenko commented 10 years ago

does not make sense... could you please show exactly the bmvc markup and Model that you used?

sgentile commented 10 years ago
@(f.FormGroup().Class("row").CustomControls(Html.Bootstrap().Div(Html.Bootstrap().DropDownListFor(m => m.Person.RelationshipTypeName, new SelectList(Model.RelationshipType, "Name", "Name")).Label()).Xs(5)))
@(f.FormGroup().Class("row").VisibleDependsOn(model => model.Person.RelationshipTypeName, "Other").CustomControls(Html.Bootstrap().Div(Html.Bootstrap().TextBoxFor(model => model.Person.OtherRelationShip).Label()).Xs(5)))
DmitryEfimenko commented 10 years ago

I just tested your code. It works fine for me with the code I have. I'm going to close this issue and if someone else has issue with it as well, I'll revisit.