titanium alloy get value of field in view -


i've been building first titanium alloy app , have 5 step signup form has different form fields spread across 5 views. on last step want post values of form elements. best way access each fields value? eg. in screen5 how value of $.name field in screen1 view?

here of code:

<scrollableview id="indexsv" showpagingcontrol="false" scrollingenabled="false" top="0">             <require src="screen1" id="screen1"></require>             <require src="screen2" id="screen2"></require>             <require src="screen3" id="screen3"></require>             <require src="screen4" id="screen4"></require>             <require src="screen5" id="screen5"></require>         </scrollableview> 

and here how screens structured:

<alloy> <view>     <label top="20">your name:</label>     <textfield top="5" id="name" />     <button top="20" right="10%" id="btnnext" width="120" onclick="next" class="next">next step</button> </view> </alloy> 

currently can think of following 2 ways:

1. define global json object in alloy.js :

in alloy.js define global variable followed:

alloy.globals.signupvalues = {   name : "",   email : "" };  

now in controller of screens, assign fetched value alloy.globals.signupvalues. screen1's controller like:

function next() {   alloy.globals.signupvalues.name = $.name.value; } 

and can fetch values in desired screen using :

var signupjson = alloy.globals.signupvalues; 

2. using callbacks in required view : can trigger function in controller of require screen , access response send view's controller main controller. can :

in main controller :

$.screen1.callback(function(name) {   $.screen5.initname(name); //pass name value screen5's controller }); 

in screen1's controller :

var nextcallback; exports.callback = function (callback) {   nextcallback = callback; };  function next(e) {   nextcallback($.name.value); } 

in screen5's controller :

var name; exports.initname = function (nameval) {   name = nameval; }; 

p.s : imo, option 1 cleaner , easy maintain.


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -