Menu

Show or hide field based on radio button.

2016-11-04
2017-11-21
  • Steven Brown

    Steven Brown - 2016-11-04

    Hello,

    I have added several custom fields to the new request page. My goal was to have a radio button with a "yes" option and a "no" option. When the user selects "yes" a new field appears which the user must fill out. If the user selects "no" the field hides (if it was being shown).

    I have all of the fields and buttons on the page, but I cannot figure out how to hide or show fields based on the radio button selections. Can anyone provide guidance on how to accomplish this? Thank you.

     
  • Daniel Villasenor

    Hi Steven !

    I am trying to do something similar to what you want. I am currently working on the Incidents module and what we need is to have a combo box with a type of incident and depending on that selection the impact combo is going to be filled in different ways.

    I managed to achive this functionallity first of all by adding a new field callled "Type", and then creating another class below the Incident class in the datamodel XML, and changing the definition of the field Impact to an ExternalKey pointing to the class I created.

    This has worked for me but caused another problem. The calculation of the priority stopped working I know why but I am still trying to figure out how to solve it.

    Maybe this is not the best way to make this but it may point you in the right direction and also maybe you can help me with my problem.

    I am attaching the datamodel I modified for you to see the changes.

    I really hope this help you a little.

    Greetings.

     
  • APO

    APO - 2017-11-21

    I tried to do the same thing. I ended up adding a hidden field for state and building a lifecycle with two states. One state had the original radio button. Clicking the button was supposed to change states. Didn't work. Added a stimulus type UserAction and then it sort of worked. Clicking the new button changed states and displayed the form with additional information, however the original form data was written to the database so if you cancelled out of the second form you had a DB record with partial information. Not very clean. Haven't solved it yet.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.