Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-11083] Feature: Bind Events in Control Creation & Enable Code Chaining

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 3.0.0
Fix Version/sn/a
ComponentsiOS
LabelsSupportTeam
ReporterEduardo Gomez
AssigneeUnknown
Created2012-09-24T15:55:39.000+0000
Updated2018-02-28T20:04:07.000+0000

Description

Feature request

Bind Events in Control Creation & Enable Code Chaining

Customer's remarks

I would like the ability to bind events to controls in the property list during creation. This would clean up my code by freeing me from creating a variable for every control, when the only purpose for the variable is assigning an event. Secondly, when a method is called on an object, the return of the method should be the control so you can chain your code.

Sample

var win = Ti.UI.createWindow();
var lbl =Ti.UI.createLabel({
    text: 'test'
});

lbl.addEventListener('click', function({ alert(this.text); });

win.add(lbl);

win.open()

Could become

Ti.UI.createWindow().add(Ti.UI.createLabel({
      text: 'test',
      eventClick: function(){ alert(this.text); } 
}).open();

Comments

  1. Pedro Enrique 2015-02-10

    This can easily be done using plain JavaScript. Take a look at this solution and see if it's something you can work with. Feel free to modify it and customize it for your own use. https://gist.github.com/pec1985/3758713

JSON Source