Skip to Content
0

Sap ui5 check box selection

Jul 19, 2017 at 05:21 AM

51

avatar image
Former Member

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
0

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
Former Member

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??

0

yes you can!

this.byId("id1").mProperties.selected

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

0

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

0
Former Member

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

0

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

Verify the ID in the Elements tab in Debugger console.

Regards.

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

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.

Regards,

Sharath

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

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.

0

Agreed. Local json model is better option.

0