cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot read property '0' of undefined

SandipAgarwalla
Active Contributor
0 Kudos

Hi

This is the error I get when I try to assign an handler to the button press


fields: [new sap.ui.commons.TextField({value:"A22",editable:false,layoutData:new sap.ui.commons.form.GridElementData({hCells: "2"})}),

            new sap.ui.commons.Button({

            text:"Change",

            press: this.showF4Help,

            layoutData:new sap.ui.commons.form.GridElementData({hCells: "2"})})

            ],

ON press, it should open a dialog box displaying certain items.

The "showF4Help" is defined as a separate method in the view definition which create the layout & UI elements for the dialog.


The function is defined as,

showF4Help: function(oEvent){

<something goes here>

}

wF4HelpForTow is definWhat

What could be wrong here?

Regards

Sandip

Accepted Solutions (1)

Accepted Solutions (1)

former_member91307
Contributor
0 Kudos

Hi Sandip,

This error is beacuse the function is not visible in this context.

Good practice would be to have the event handler in controller.

Below example has both scenarios mentioned above

http://jsbin.com/uxokuc/237/edit

Thanks and Regards, Venkatesh

SandipAgarwalla
Active Contributor
0 Kudos

Thanks Venkat

Well, I could define the handler in the controller - however on click of the button - i need to create the dialog layout & its element on the fly. So i kept the dialog content creation in the view itself ?

Is there a better way to handle this?

Regards

former_member91307
Contributor
0 Kudos

Hi Sandip,

The creation part could be done either in view or in controller.

Below is example with changes

http://jsbin.com/uxokuc/238/edit

ValueHelp field control might help acheive F4 value help

SAPUI5 SDK - Demo Kit

Thanks and Regards, Venkatesh

qmacro
Developer Advocate
Developer Advocate
0 Kudos

It is indeed a common dilemma but recently (1.16) there are Fragments which are pieces of UI that can be defined separately, and ideal for defining dialogs which you'd otherwise have to instantiate, as you say, programatically on demand, rather than in the view directly.

http://localhost:8888/sapui5/latest/docs/#docs/guide/Fragments.html

dj

SandipAgarwalla
Active Contributor
0 Kudos

HI DJ

Thanks a lot for your reply.

The "Fragments" concept look great.

What is the best way to handler such situation where you need to show pops/dialogs/overlay containers multiple times (diff content), lets says on click of each row of a table - you wan to display the details.

1) Do you generate this pop ups on the fly in the event handler?

2) Or, you create the pop up with the UI elements in the view, keep it instantiated and just call it to open in the event handler?

3) Do you assign an ID to the pop -up and re-use the same instance, or have the framework generate a new instance with a id everytime -

Thanks

Sandip

qmacro
Developer Advocate
Developer Advocate
0 Kudos

I use a Singleton patten usually with a model to hold the changing content

SandipAgarwalla
Active Contributor
0 Kudos

Thanks DJ

Would you mind explaining the pattern you use? Some details would be great

Thanks

Sandip

qmacro
Developer Advocate
Developer Advocate
0 Kudos

Contain the instantiated fragment in the controller object, and then only create it if it doesn't already exist, basically. Specifically, looking at the usual Singleton documentation, it's a lazy instantiation.

HTH

dj    

Answers (0)