javascripthtmlfragmentsapui5

SAPUI5 Fragment won't open


I am trying to make a popup/fragment in SAPUI5 that shows comments listed in a database. I know the database works fine along with the calls. When i click on the button that is supposed to open the fragment, nothing happens.

Controller.js

_getDialog: function() {
    // associate controller with the fragment
    this.oCommentDialog = sap.ui.xmlfragment("really.long.destination.fragment.CommentDialog", this);
    this.getView().addDependent(this.oCommentDialog);

    // toggle compact style
    jQuery.sap.syncStyleClass("sapUiSizeCompact", this.getView(), this.oCommentDialog);
 
    //this.oCommentDialog.open;
    return this.oCommentDialog;
},

onCommentDialogPress: function(oEvent) {
    var oCommentDialog = this._getDialog();
    console.log(oCommentDialog);
    oCommentDialog.open();
}

CommentDialog.fragment.xml

<core:FragmentDefinition
    xmlns="sap.m"
    xmlns:core="sap.ui.core">
    <Popover
        title="Comments"
        class="sapUiContentPadding"
        placement="Top">
        <footer>
            <Toolbar>
                <ToolbarSpacer/>
                <Button
                    id="email"
                    text="Email"
                    press="handleEmailPress" />
            </Toolbar>
        </footer>
    </Popover>
</core:FragmentDefinition>

Here is the error i get in the console.

Uncaught TypeError: oCommentDialog.open is not a function

The line above the error from console.log(oCommentDialog); has a return function or prototype. So I know this is working, or at least I think so.

I have already checked to see if open() is set to something else in code, and it is not.


Solution

  • You are using a Popover, which does not have an open method. If you want to open a Popover you need to use the myPopover.openBy(control).

    You can find the documentation here

    The fact that you are trying to use open, and considering your variable name, it looks like you might be looking for the Dialog control.