Skip to content

Latest commit

 

History

History
54 lines (42 loc) · 1.46 KB

defining-dialogs-as-fragments-0457545.md

File metadata and controls

54 lines (42 loc) · 1.46 KB

Defining Dialogs as Fragments

You can use fragments for the definition of dialogs.

Context

To use fragments for defining popups, just let the root control of the fragment be a dialog or similar control.

The following shows an XML fragment dialog example:

<Dialog xmlns="sap.m" title="XML Fragment Dialog">
    <TextView text="{/dialogText}" />
    <buttons>
        <Button text="Close" press="closeDialog"/>
    </buttons>
</Dialog>

Other fragment types are used the same way to define, for instance, a dialog as fragment.

For example, in JS fragments, the createContent() method returns a dialog control:

// fragment is located in a file named: testdata/fragments/JSFragmentDialog.fragment.js,
sap.ui.define(["sap/m/Dialog", "sap/m/Input", "sap/m/Button"], function(Dialog, Input, Button) {
    return {
        createContent: function(oController) {
            var oDialog = new Dialog({
                title: "JavaScript Fragment Dialog",
                content: [
                    new Input({
                        text: "{/dialogText}"
                    })
                ],
                buttons: [
                    new Button({
                        text: "Close",
                        press: function(){
                            oDialog.close();
                        }
                    })
                ]
            });
            return oDialog;
        }
    }
});