0

I have a form where i have to display certain fields based on the value of the checkbox.

below is the code in my view

        @checkbox(
        userModelForm("isStudent"),
        '_label -> <font color = "grey"> Student</font>,
        '_showConstraints -> false
    )

if this checkbox is selected i need to display the following input text if not this should be hidden

        @inputText(
            userModelForm("StudentId"),                
            '_label -> <font color = "grey" > Student Id </font> ,  'class -> "form-control",
            '_help -> "Realtors, please enter Your Student id.",
            '_error -> userModelForm.globalError
        )

Thanks

1 Answers1

0

I would put the @inputText in a div that is hidden,<div style="display: none;"> then use javascript to show/hide it. If you have many hidden divs, I would apply the styling from a .css file. (Inline isn't very good)

You will need to add an id to the checkbox.

        @checkbox(
    userModelForm("isStudent"),
    '_label -> <font color = "grey"> Student</font>,
    '_showConstraints -> false,
    'id -> "show-student-checkbox"
)

Then take a look at this, get selected value of dropdown You will then have to write if tests that unhides the div.

Take a look at this aswell if you are unsure about hiding + unhiding divs

Community
  • 1
  • 1
NoClueBlue
  • 451
  • 4
  • 17