cancel
Showing results for 
Search instead for 
Did you mean: 

Click event in dropdown

rohit3611
Contributor
0 Kudos

Hi,

how to use a expand or press or click event on Dropdownbox.

i have only one value so want to capture these events and do some logic.

Best regards,

Rohit

Accepted Solutions (1)

Accepted Solutions (1)

former_member182862
Active Contributor
0 Kudos

HI Rohit

Is it that because there is only one item in the dropdownbox that you do not get the change event?

-D

rohit3611
Contributor
0 Kudos

yes?

Do we have way to override select or click event.

Best regards,

Rohit

former_member182862
Active Contributor
0 Kudos

HI Rohit

Is this what you are looking for ?

Example

Thanks

-D

rohit3611
Contributor
0 Kudos

Hi Dennis,

I used the below way and it also worked the same way.

Thanks are your help.

Best regards,

Rohit

<!DOCTYPE html>

<html><head>

    <meta http-equiv='X-UA-Compatible' content='IE=edge' />

    <title>test</title>

    <script id='sap-ui-bootstrap' type='text/javascript'

        src='/sapui5/resources/sap-ui-core.js'

        data-sap-ui-theme='sap_goldreflection'

        data-sap-ui-libs='sap.ui.commons'></script>

<script>

    var oModel = new sap.ui.model.json.JSONModel(

        { "countries": [

            {

                "name"     :     "Germany",

                "short"     :     "DE"

            },

  {

                "name"     :     "India",

                "short"     :     "In"

            }

     ]

});

   

    var oDD = new sap.ui.commons.DropdownBox({

  change : function(oEvent){

  alert(sap.ui.getCore().byId(this.getSelectedItemId()).getBindingContext().toString());

  }

  });

    oDD.setModel(oModel);

  oDD.bindItems("/countries", new sap.ui.core.ListItem({text: "{name}", additionalText: "{short}"}));

  // oDD.onclick(alert("Test"));

   oDD.addEventDelegate({

        onselect:function() {

           oDD.onclick(alert("Test"));

        }

    });

    oDD.placeAt("content");

   

</script>

</head>

<body class='sapUiBody'>

    <div id='content'></div>

</body>

</html>

former_member182862
Active Contributor
0 Kudos

Hi Rohit

Your solution is sound.

If you are going to use this control in many other places. Then i think it is better to extend the dropbown box control in this manner.

Example

-D

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Rohit,

Specify event for dropdown selection in GET_P_XXX method of that context node.

METHOD get_p_fieldname.

   CASE iv_property.

     WHEN if_bsp_wd_model_setter_getter=>fp_fieldtype.

       rv_value = cl_bsp_dlc_view_descriptor=>field_type_picklist.

     WHEN if_bsp_wd_model_setter_getter=>fp_onclick.

       rv_value = 'FIELD_SELECTED'.

   ENDCASE .

ENDMETHOD.


Now define the event 'FIELD_SELECTED' in event handlers and write your logic.


Thanks,

Ritu