cancel
Showing results for 
Search instead for 
Did you mean: 

How to access control model from 'blur' browser event

former_member182374
Active Contributor
0 Kudos

Hello Experts,

I have a textField column in a table.

I need to listen to the 'blur' event of each textField cell.

I use the following code:

<textField>.attachBrowserEvent("blur", onBlur);

The code works and I can get the textField's value (by using this.getLiveValue()).

However, I need to get other property from the model (from the same row).

How can I get the model from the 'blur' function? (get the exact row properties)

I can always add a hidden column and use jQuery sibling etc to get the value but I'm sure there is more elegant way (-:

Regards,

Omri

Accepted Solutions (1)

Accepted Solutions (1)

kai2015
Contributor
0 Kudos

  .....attachBrowserEvent("blur", function(e) { 

  var oInput = sap.ui.getCore().byId(e.currentTarget.id);

    var sPath = oInput .getBindingContext().sPath;

}

In the variable sPath is now the path to the current row.

Hope it helps.

If not working, please read this:

kind regards, Kai

former_member182374
Active Contributor
0 Kudos

Hi Kai,

Thanks but the code doesn't work.

'e.currentTarget.id' and 'this.getId()' will return the id of the object.

When attaching browser events 'this' is actually the ui5 control and control methods like  getBindingContext() are available. The problem is that  'getBindingContext()' method returns null.

I can create JSBin but I think it is not needed in this case.

Regards,

Omri

Qualiture
Active Contributor
0 Kudos

If 'this' is the UI5 control that's firing the event, then  why not simply use :

this.getBindingContext().getObject();

This will give you the current model's node object

kai2015
Contributor
0 Kudos

I think so, because it's working in my case.

Please create an example, so that I can see your data binding.

former_member182374
Active Contributor
0 Kudos

Hi Robin,

this.getBindingContext().getObject() doesn't work see jsbin:

http://jsbin.com/papata/4/edit?html,console,output

Regards,

Omri

former_member182374
Active Contributor
0 Kudos

Hi Kai,

See jsbin:

http://jsbin.com/papata/4/edit?html,console,output

From the 'theDate' cell I need to get the corresponding 'someText' or 'anotherText' fields of the model.

Regards,

Omri

kai2015
Contributor
0 Kudos

Hi Omri,

I've found the problem ... there is no ContextBinding, when you use named binding.

So, if you bind the model without a name like the following it is working:

oTable.setModel(oModel);

oTable.bindRows("/modelData");

I know that named binding is important, but I don't know why it's not working with that.

Maybe an expert can explain that, or is it just a known bug???

maximilian_lenkeit
Participant
0 Kudos

This is not entirely correct. The method getBindingContext does take a parameter, which is the model name. So you can do something like this.getBindingContext("tblModel")

Here's the working example: http://jsbin.com/qedupuhepo/2/

- Max

kai2015
Contributor
0 Kudos

Hehe, thank you!!

And what if I don't know the current Model for that field?

Is there any way to get that modelname? To make the getContextBinding function more dynamic...

Qualiture
Active Contributor
0 Kudos

Hi Omri,

You are using a named model "tblModel", in that case you need to specify the model name as an argument for the binding context too:


var o = this.getBindingContext("tblModel").getObject();

former_member182374
Active Contributor
0 Kudos

Maximilian thanks! this solves my problem

Kai, Robin - thanks (i know the code is not generic but for my scenario it is OK)

maximilian_lenkeit
Participant
0 Kudos

Not that I'm aware of. Note that a control can have multiple binding contexts, potentially one for each model that it has access to. Considering that, there cannot really be any logic to get *the* binding context. Anyhow, you should always know the model name or reconsider your design

- Max

Answers (0)