Reputation: 791
I'm using a widget. I'm creating it in the index.js controller. I would like to be able to access the widget's event listeners so I can tell when the value of the widget changes, to change colours in index.js elements.
Can anyone help me?
Like this question
Upvotes: 1
Views: 357
Reputation: 3866
All Alloy controllers, including those of Widgets extend Backbone.Events and are therefor event dispatchers. The scenario you talk about is an excellent use case for these. Let me give you an example:
widget.xml
<Alloy>
<TextField onChange="onTextFieldChange" />
</Alloy>
widget.js
function onTextFieldChange(e) {
$.trigger('change', {
value: e.value
});
}
index.xml
<Alloy>
<Window id="win">
<Widget src="myWidget" onChange="onWidgetChange" />
</Window>
</Alloy>
index.js
function onWidgetChange(e) {
$.win.backgroundColor = e.value;
}
Upvotes: 3