-1

I have the following select in a table in my xml view.

Table:

<Table id="variables" 
                  rows="{
                    path: 'modelname>/ZDATSet'
                }">
...

Select:

<m:Select
          selectedKey="{modelname>Datetype}"
          items="{
                path: 'modelname>/ZTYPESet'
          }">
          <core:Item key="{modelname>Datetype}" text="modelname>Datetypetxt}" />
</m:Select>

Furthermore I have a button in an other row in the table. In the press-function I want to read the currently selected key of the select-box.

If I try it with

var button = oEvent.getSource();
var context = button.getBindingContext("modelname");
var datetype = context.getProperty("Datetype");

I only get the preselected value but not the change from the user input. (Same problem with an text input in the row)

I already put data-sap-ui-xx-bindingSyntax="complex" in the index.html

enter image description here

alexander-fire
  • 1,082
  • 4
  • 27
  • 52
  • 1
    Your code seems ok... are you by any chance using an ODataModel with one-way binding? Or a JSONModel with two-way binding? The former could give issues, the latter should work just fine – Qualiture Mar 29 '16 at 11:03
  • Does this answer your question? [Input validation not working with v2.ODataModel in contrast to JSONModel](https://stackoverflow.com/questions/47468688/input-validation-not-working-with-v2-odatamodel-in-contrast-to-jsonmodel) – Boghyon Hoffmann Feb 22 '21 at 14:35
  • As explained in the above [linked answer](https://stackoverflow.com/a/47472757/5846045), the default binding mode in `v2.ODataModel` is `"OneWay"`. You need to switch to `"TwoWay"` explicitly in order to allow storing the changed value from the UI to the ODataModel. – Boghyon Hoffmann Feb 22 '21 at 14:38

4 Answers4

1

I found the solution now.

I thought <script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" data-sap-ui-xx-bindingSyntax="complex" ... should be enough for the default two way binding.

Now I added oModel.setDefaultBindingMode(sap.ui.model.BindingMode.TwoWay); to the model and it works fine.

alexander-fire
  • 1,082
  • 4
  • 27
  • 52
0

If your button is in the same row you could do something like this in its press event:

onPress:function(oEvent){
  var button = oEvent.getSource();
  var context = button.getBindingContext("modelname"); //Points to the current row
  var datetype = context.getProperty("DateType");    
  ...
}

If the button is outside of the table you have to give us more details: Which Table are you using and how is it configured, do you want to read the value of the selectbox in the currently selected row? Add more code!

schnoedel
  • 3,918
  • 1
  • 13
  • 17
  • The button is inside the table. I already tried it like your way, but with that code, I only get the prefilled value. If the user change the selected value, it will not be updated. – alexander-fire Mar 29 '16 at 10:49
0

Based on your code snippet, you are using model binding to set the items and the selected key of your Select.

In the Button press handler you can get the current value from the binding context:

onPress: function (oEvent) {
    oEvent.getSource().getBindingContext("modelname").getProperty("Datetype");
}
hirse
  • 2,394
  • 1
  • 22
  • 24
-1

Here once you set the selectedKey property in SelectionInputType.COMBOBOX, you can take value as below.

oController = this; var view = oController.getView(); var oModel = view.getModel(); var data = oModel.getData();

  • 1
    The issue was that the question author was using `v2.ODataModel` which has `"OneWay"` as its default binding mode. I.e. the model won't have the changed value in `oModel.getData()`. – Boghyon Hoffmann Feb 22 '21 at 14:41