Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8187313

Property for preventing ComboBox deselection

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • None
    • javafx
    • None

      Any JavaFX ComboBox allows the selection of the value null by clicking an item in the dropdown while holding down the cmd key (on mac) or CTRL (on Windows). This is not always desired, and I request this is made configurable.

      Lets look a two different use cases:
      Use case 1: The user is asked "How much luggage do you have?". We add a null item which represents 0 suitcases and shows up as a blank choice, as well as two non-null items "1 suitcase" and "2 suitcases". Here a null choice is a valid, meaningful answer.
      Use case 2: The user is asked "Would you like to receive our newsletter?". We add two items "Yes" and "No" and preselect "No", so users have to actively say yes to receiving the newsletter. In this case a null choice does not make any sense.

      I am developing a use case similar to use case 2, and the problem is, even though I am not adding a null item, and even though I am preselecting, JavaFX still allows users to sneak in a null reply by holding down cmd or CTRL and clicking an item in the ComboBox's dropdown.

      I recommend adding a property for controlling whether deselection is allowed so we can optionally prevent null values in use cases like this. It might logically belong to the selection model — perhaps the selection model could have a property called nullSelectable an corresponding isNullSelectable() and setNullSelectable() methods for controlling it.

            Unassigned Unassigned
            risaksen Randahl Isaksen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: