Skip to Content
0

checkboxes and input box in table with oData

Jan 16 at 07:34 PM

177

avatar image

I created a table in Web IDE that has a checkbox and input box that by default shows "100%" when checkbox is selected. It was working before I added data from a json but now that I made the column list item a template taking in data from the json on some of the columns, the input box does not fill in when selecting checkbox.

this the wanted result

If I use something like message box, it does the correct output when selecting checkbox.

<code>sap.m.MessageBox.alert("100%")
sap.m.MessageBox.alert("0%")

I binded the event to the checkbox under select. This is the code for the checkbox.

<code>    percentCheck: function(oEvent) {
        //inputText is the input Text box  
        var inputText = this.getView().byId("inputPercent");
        var isSelected = oEvent.getParameter("selected");

        if (isSelected) {
            inputText.setValue("100%");
        } else {
            inputText.setValue("");
        }
    }
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Jun Wu Jan 16 at 08:09 PM
1

usually don't go to the ui control to manipulate .

always go through binding.

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

so I tried to do the binding but it is still not working.

controller side:

estimatePercentageSelect: function(oEvent) {
var cxt = oEvent.getSource().getBindingContext();
      var obj = cxt.getObject();
      if (obj.selected) {
        obj.percent = "100%";
      }
      else{
      	obj.percent = "";
      }
}

xml side:

	<CheckBox id="checkEstimate" select="estimatePercentageSelect"/>
	<Input value="{percent}" width="100%" id="inputPercent"/>
0

cxt.getModel().setProperty("percent","100%",ctx)

give it a try.

0

Thanks!!! cxt.getModel().setProperty("percent","100%",cxt) worked!!

I debugged and saw the obj.selected was showing undefined, so I used the event parameter to show if checkbox was selected or not

estimatePercentageSelect: function(oEvent) {
var isSelected = oEvent.getParameter("selected");
var cxt = oEvent.getSource().getBindingContext();
      
if (isSelected) {
      cxt.getModel().setProperty("percent","100%",cxt);
      }
      else{
      	cxt.getModel().setProperty("percent",null,cxt);
      }
}
0
VIPLOVE KHUSHALANI Jan 17 at 06:53 AM
0

Hi

I think its because you have the binding now , you are not changing the bind value, you are changing at the level of the ui control ..

Jun Wu is correct try using the bindings , don't set value using setValue function ..

thanks

Viplove

Share
10 |10000 characters needed characters left characters exceeded