How to access page fragment custom properties programmatically?

889 Views Asked by At

How do I access page fragment's custom properties within an event handler of one of its widget? For example, I'm trying to access them in an OnLoad event of the page fragment itself like this:

function SumBoxOnDataLoad (widget) {
    widget.descendants.TextBox.value = Currencies [widget.properties.currency]+widget.properties.value;
}

...and widget.properties is undefined. According to the API, even if I use widget.root, which points to the same page fragment, there's nothing there resembling properties to work with.

1

There are 1 best solutions below

0
On BEST ANSWER

It depends on what you are trying to do. Basically, there are two major use cases:

  1. Workaround lack of global bindable variables in App Maker. Page Fragment itself (not an instance of Page Fragment on particular page) has its own properties, that can be used globally across the app. This hack/feature is used in Starter App template to track menu state on app level.
...
var x = app.pageFragments.MyPageFragment.properties.MyCustomProperty;
...
  1. Use properties of particular Page Fragment instance:
// access from current page:
var x = app.currentPage.descendants.MyPageFragmentInstance.properties.MyCustomProperty;

// ...or
var x = app.pages.MyPage.descendants.MyPageFragmentInstance.properties.MyCustomProperty;

// access in page fragment instance's event (onAttach for example)
var x = widget.parent.properties.MyCustomProperty;

// access in page fragment instance descendant's event
var x = widget.root.parent.properties.MyCustomProperty;

Further reading:

Page Fragment Custom Properties