Skip to main content

How to get the selected value of CMS_INPUT_COMBOBOX

Comments

1 comment

  • Zendesk API User
    Author: mbergmann - 5/13/2016 9:21

    Hi Kavin,

    you are working on the "wrong side" - namely the input component UI model - but you have to use the "data side".

    As an INPUT_COMBOBOX can contain different types of date depending on its GOM definition, its general value type is an Option which acts as a wrapper object for the real data. From an Option, you get the value just using getValue().

    I broke it down into seperate steps to make it clearer:

    //lang may be null for language independent input components

    FormField<Option> formField = (FormField<Option>) dataset.getFormData().get(lang, "tt_contact");

    Option option = formField.get();

    Object value = option.getValue();

    // depending on the definition of the combobox, you get different types here.

    // e.g. if the combobox has INCLUDE_OPTIONS type=Database (looks to me this is the case) you will get an Entity

    Entity contactEntity = (Entity) value;

    // OR, if you use "hardcoded" options <ENTRIES><ENTRY>...</ENTRY><ENTRY>...</ENTRY></ENTRIES> you get a String

    String stringEntry = (String) value;

    Michael

    0

Please sign in to leave a comment.