TwitterBootstrapMvc icon indicating copy to clipboard operation
TwitterBootstrapMvc copied to clipboard

VisibleDependsOn does not hide field initially

Open pennstatephil opened this issue 11 years ago • 8 comments

When using the following:

    @f.FormGroup().RadioButtonsFromEnumFor(m => m.courseLength).DisplayInlineBlock()

    @f.FormGroup().TextBoxFor(m => m.courseLengthDescription).VisibleDependsOn( m => m.courseLength, (BL.Models.CourseLength.Other).ToString())

the textbox field is visible when the courselength item is not "other" initially. When I change the value to something else that isn't "other", it disappears. If I select "other" and then select off it, the field appears/hides as desired. This bug only happens on initial page load.

pennstatephil avatar Jan 23 '14 20:01 pennstatephil

Workaround:

    @f.FormGroup().Id("courseLengthButtons").RadioButtonsFromEnumFor(m => m.courseLength).DisplayInlineBlock()

    @f.FormGroup().Id("otherLengthBox").TextBoxFor(m => m.courseLengthDescription).VisibleDependsOn( m => m.courseLength, (BL.Models.CourseLength.Other).ToString())

and

<script type="text/javascript">
    $(document).ready(function () {
        if ($("#courseLengthButtons input:checked").val() == "Other") {
            $("#otherLengthBox").show();
        }
        else {
            $("#otherLengthBox").hide();
        }
    });
</script>

pennstatephil avatar Jan 23 '14 21:01 pennstatephil

I can't reproduce the issue... Tried with exactly your code.

DmitryEfimenko avatar Feb 02 '14 11:02 DmitryEfimenko

VisibleDependsOn does not hide field initially when enum has not zero value

MiroslawSlanda avatar Jun 01 '16 16:06 MiroslawSlanda

@MiroslawSlanda please share with me a sample project showing the issue.

DmitryEfimenko avatar Jun 01 '16 17:06 DmitryEfimenko

public enum RelationType { OneProduct = 1, Multiple = 2, NotLinked = 3, }

@f.FormGroup().RadioButtonsFromEnumFor(m => m.RelationType) @Html.Bootstrap().Div(...).VisibleDependsOn(m => m.RelationType, RelationType.OneProduct.ToString()) @Html.Bootstrap().Div(...).VisibleDependsOn(m => m.RelationType, RelationType.Multiple.ToString())

MiroslawSlanda avatar Jun 01 '16 17:06 MiroslawSlanda

This was an issue a while back and it was fixed. Do you have latest? Particularly latest javascript file?

DmitryEfimenko avatar Jun 01 '16 18:06 DmitryEfimenko

Yes, I have. I am taking about situation when I not choose any RelationType. I can show this issue on TwitterBootstrapMvcJs.js in line 263 has: if ($(selector).is(':radio')) { $(selector + ':checked').change(); } else { $(selector).change(); } You can fix this issue like this (but content will be flicker): $(selector).change(); if ($(selector).is(':radio')) { $(selector + ':checked').change(); }

MiroslawSlanda avatar Jun 01 '16 19:06 MiroslawSlanda

you do not have latest version of javascript file. Whenever you update via Nuget the latest javascript file gets downloaded in folder Scripts. Make sure that's the file you are using. If it is, please let me know exactly the version of BMVC that's in use.

DmitryEfimenko avatar Jun 01 '16 22:06 DmitryEfimenko