Custom widget get current page.

0
Hello everyone, I am building my first widget and I have a problem finding a way to get the current page ( the page on which the widget is placed ). Also, is it possible to add a Page parameter to the widget? Edit: Can the widget "show" a Page if you have that page name as a string?
asked
3 answers
3

Hi Volen,

Get the Current Page Name: as Rom suggests, you can get the current page through _formBase and path, or you can use a property of (`mx.router`) and use:

mx.router._contentForm.path // --> "Administration/Homepage.page.xml"

Include a Page as a Widget Property: In the documentation for the widget specification, you can see that you can include a Form property, which translates into the same name that you see in (`path`). https://docs.mendix.com/refguide/xml-reference-guide#5-2-4-form. In your widget, this translates into a property that lets the Mendix developer choose the page through a dialog, and whose key in your widget instance will map to a string value similar to what you see in (`path`), i.e. something like "Administration/Homepage.page.xml". You can use that value in conjunction with (`mx.ui`) in the Client API to open forms through JS, like this:

mx.ui.openForm("MyFirstModule/Puppies.page.xml", {
    location: "popup",
    callback: function(form) {
        console.log(form.id);
    }
});

 

answered
1

Hi Volen,

Regarding your second question you can send a string parameter to the widget, then it is up to the person who places the widget on a certain page to set that parameter correctly. If you want to open a page from the widget it best to use a microflow. You can set a microflow as a parameter and open a page in this microflow.

Hope this helps,

Andrej

answered
0

It should be pretty easy to find. If you look at the documentation, more specifically here, you will see that your widget (through _WidgetBase) has a member mxform of type _FormBase and _FormBase has a member path which contains the page.

answered