Dropdown Menus & Free Text for "Other"

Dropdown Menus & Free Text for "Other"

Matthew2051Matthew2051 Posts: 13Questions: 1Answers: 0

Hello,

Used the editor a while ago and need to develop another solution in the coming weeks. Before I get started I was wondering if there are any examples out there where if the user has a dropdown list to select a value from and there is an 'Other' option in the list, a free text box would appear or at least be mandatory to be filled in if the 'Other' value is selected.

Thank you for any help on this.

Kind Regards,
Matthew.

Answers

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Hi Matthew,

    Good question - currently no there isn't an example of this specific feature. What you would do is initialise all of the fields as normal, and then use a change event listener to trigger the Other field's visibly using the show() and hide() methods.

    For example:

    $('select', editor.field('mySelect').node()).on( 'change', function () {
      if ( $(this).val() === "Other..." ) {
        editor.show( 'optionalFieldName' );
      }
      else {
        editor.hide( 'optionalFieldName' );
      }
    } );
    

    Allan

  • Matthew2051Matthew2051 Posts: 13Questions: 1Answers: 0

    Thank you Allan! :)

This discussion has been closed.