Skip to Content

Sap ui5 check box selection

Jul 19, 2017 at 05:21 AM


avatar image

I have generated 12 check boxes for each month in the year through code in the controller. I also have a recal button on the same view which on press I want to determine the check boxes selected to make an Odata call and pass the selection. My code this.byId("chkbox1").getSelected() is not working inside the press event of the recal button.

Please help me what am I doing wrong??

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Bilen Cekic Jul 19, 2017 at 09:57 AM

better do in shortway,

create a model with 12 parameters, and bind to checkboxes. Whenever they are checked, values will be updated, you can just check the model itself.

var oModel = new sap.ui.model.json.JSONModel({
jan:"",feb:"",.....december:"" }); this.getView().setModel(oModel,"CHKLIST");
Show 5 Share
10 |10000 characters needed characters left characters exceeded

Just to confirm is there no way to get the value of the check box selected directly outside the select event without updating the model??


yes you can!


will return you true or false. you can use for all checkboxes.


You can always get the control by ID and get its value.


How.. That's what I have been trying without any success..


this.getView().byId("ID provided while creation of the checkbox")

Verify the ID in the Elements tab in Debugger console.


Sharath M G Jul 19, 2017 at 07:53 AM

First, when you are generating the check box, assign a unique ID to each checkbox.

Assign an event handler for the checkbox - "select" event. In the event handler, store the id/index of the checkbox in an array.

Have one event handler for all check boxes.

Now, as and when the user clicks on the checkbox, the event handler gets triggered and the id or any other details of the clicked checkbox can be maintained in the array.

Note: Array should be declared outside the event handler. Use debugger console to verify the process.



Show 2 Share
10 |10000 characters needed characters left characters exceeded

Declaring the array outside the event handler is making it global, which I read is not recommended. The other option is to update a model in the select event of the check box and then access the model in the press event of the button to make the Odata call. However I am looking for help to achieve this through code. Please provide some sample code for this. Thanks.


Agreed. Local json model is better option.