[ALOY-904] Requesting widgets/requires to receive reference to their parent

GitHub Issuen/a
TypeNew Feature
Affected Version/sn/a
Fix Version/sn/a
Labelsproxy, require, widgets
ReporterFokke Zandbergen
AssigneeTim Poulsen


Following the discussion in #ALOY-903 I'd like to request that widgets and required controllers receive their parent element as an argument.

Why I need this... since Alloy 1.3.0

As I've understood from [~tlukasavage] this is similar but not exactly the same as the internally used __parentSymbol. I think this is in particular true for proxy elements since Alloy 1.3.0. Earlier, these received the __parentSymbol property and were bound to their parent from within the widget. Since Alloy 1.3.0 however, the binding takes place in the controller that hosts the table and the widget no longer receives the property:
    $.__views.is = Alloy.createWidget("nl.fokkezb.infiniteScroll", "widget", {
        id: "is"
    onEnd ? $.__views.is.on("end", onEnd) : __defers["$.__views.is!end!onEnd"] = true;
    $.__views.ptr = Alloy.createWidget("nl.fokkezb.pullToRefresh", "widget", {
        id: "ptr"
    onEnd ? $.__views.ptr.on("release", onEnd) : __defers["$.__views.ptr!release!onEnd"] = true;
    $.__views.table = Ti.UI.createTableView({
        footerView: $.__views.is.getProxyPropertyEx("footerView", {
            recurse: true
        headerPullView: $.__views.ptr.getProxyPropertyEx("headerPullView", {
            recurse: true
        headerView: $.__views.ptr.getProxyPropertyEx("headerView", {
            recurse: true
        id: "table"
This is fine and I guess better then before, but I'm sure it's possible to still pass the parent back to the widget?




  1. Alexey Chulochnikov 2014-02-10 It would be great if this feature request will be resolved!
  2. Tim Poulsen 2014-03-26 Attaching a project the shows how you can access the parent via the $.parent property. Tested with SDK 3.2.2.GA and Alloy 1.3.1. There are some limitations. But perhaps this existing property addresses the requested functionality?
  3. Fokke Zandbergen 2014-04-01 [~skypanther] as your project shows widgets/requires providing 'normal' views still get __parentSymbol and can use $.parent:
           $.__views.index = Ti.UI.createWindow({
               backgroundColor: "white",
               id: "index"
           $.__views.index && $.addTopLevelView($.__views.index);
           $.__views.starwidget = Alloy.createWidget("starrating", "widget", {
               top: 50,
               left: 20,
               id: "starwidget",
               max: "5",
               initialRating: "2.5",
               __parentSymbol: $.__views.index
    However, as I explained in the description, widget/requires providing proxy properties do not anymore since 1.3.x. Get the diff?
  4. Tim Poulsen 2014-04-23 PR: https://github.com/appcelerator/alloy/pull/370 Functional test Run the sample app included in the PR. In the log output, you should see the message "Widget's parent id is IAmTheParent" and there should be a red label in the window with the text "Created in the widget" which as it suggests, was defined in the code of the widget and added to the parent container using the new reference variable.
  5. Fokke Zandbergen 2014-04-24 Added a failing test to the PR.
  6. Tim Poulsen 2014-04-24 PR doesn't address requested functionality and offers no benefit over existing code. PR closed without merging.
  7. Fokke Zandbergen 2014-04-24 A workaround might be to let the widget main view to be empty do that it gets the parent and then manually attach 2nd view of the same widget. Ugly, but might work...

JSON Source