TwitterBootstrapMvc
TwitterBootstrapMvc copied to clipboard
VisibleDependsOn does not hide field initially
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.
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>
I can't reproduce the issue... Tried with exactly your code.
VisibleDependsOn does not hide field initially when enum has not zero value
@MiroslawSlanda please share with me a sample project showing the issue.
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())
This was an issue a while back and it was fixed. Do you have latest? Particularly latest javascript file?
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(); }
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.