cancel
Showing results for 
Search instead for 
Did you mean: 

checkboxes and input box in table with oData

0 Kudos

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("");
        }
    }

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor

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

always go through binding.

0 Kudos

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"/>
junwu
Active Contributor
0 Kudos

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

give it a try.

0 Kudos

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);
      }
}

Answers (1)

Answers (1)

former_member340030
Contributor
0 Kudos

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