exports.setNaam = function(args) { Ti.API.info('in setnaam'); actiefzijn.text='werkt'; }im trying to access a form element the form elements is in a other module
my setup atm is like this
app.js
(function(){ var Mods = require('/ModulePaths'); var AppWindow = require(Mods.APPWINDOW); var appWin = new AppWindow(); appWin.open(); })();AppWindow.js
var Mods = require('/ModulePaths'); var IndexView = require(Mods.INDEXVIEW), $$ = require(Mods.STYLES), Tools = require(Mods.TOOLS); module.exports = function() { var win = Ti.UI.createWindow ($$.APP_WINDOW); win.add(new IndexView()); return win; }
indexView.js
var Mods = require('/ModulePaths'); var $$ = require(Mods.STYLES), Tools = require(Mods.TOOLS); module.exports = function() { var win1 = Ti.UI.createView($$.FULL_SCREEN); var language = Titanium.Platform.locale; Titanium.App.Properties.setString('locale',language); Titanium.App.language = language; var win1 = Titanium.UI.createWindow({ title:'Settings', backgroundColor:'#ededed', navBarHidden: true, barColor: '#13386c' }); var tab1 = Titanium.UI.createTab({ icon: '19-gear.png', title:'Settings', window:win1 }); var img = Titanium.UI.createImageView({ image:'offline.png', width:15, height:15, top:160, left:30 }); win1.add(img); var actiefzijn = Titanium.UI.createLabel({ color:'#000000', text:'Account niet actief', top:160, left:50, font:{fontSize:11}, height:'auto' }); win1.add(actiefzijn); if (language=='nl') { var firstName = Titanium.UI.createLabel({ color:'#000000', text:'Profielnaam', top:10, left:30, width:100, height:'auto' }); } else { var firstName = Titanium.UI.createLabel({ color:'#000000', text:'Profile name', top:10, left:30, width:100, height:'auto' }); } win1.add(firstName); if (language=='nl') { var firstNameField = Titanium.UI.createTextField({ hintText:'Vul je profielnaam in', height:35, top:35, left:30, width:250, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED }); } else { var firstNameField = Titanium.UI.createTextField({ hintText:'Fillin your profile name', height:35, top:35, left:30, width:250, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED }); } win1.add(firstNameField); // // CREATE FIELD TWO // if (language=='nl') { var lastName = Titanium.UI.createLabel({ color:'#000000', text:'Wachtwoord', top:75, left:30, width:100, height:'auto' }); var lastNameField = Titanium.UI.createTextField({ hintText:'Vul je wachtwoord in', height:35, top:100, left:30, width:250, passwordMask:true, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED }); } else { var lastName = Titanium.UI.createLabel({ color:'#000000', text:'Password', top:75, left:30, width:100, height:'auto' }); var lastNameField = Titanium.UI.createTextField({ hintText:'Fillin your password', height:35, top:100, left:30, width:250, passwordMask:true, borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED }); } win1.add(lastNameField); win1.add(lastName); // CREATE FIELD 3 if (language=='nl') { var taal ='Nederlands'; } else { var taal ='English'; } if (language=='nl') { var landkeuze = Titanium.UI.createLabel({ color:'#000000', text:'Systeem taal '+language+' we gebruiken '+taal+'', top:140, left:30, font:{fontSize:11}, height:'auto' }); } else { var landkeuze = Titanium.UI.createLabel({ color:'#000000', text:'System language '+language+' we will use '+taal+'', top:140, left:30, font:{fontSize:11}, height:'auto' }); } win1.add(landkeuze); var hoeveel = Titanium.UI.createLabel({ color:'#000000', text:'', top:170, left:50, font:{fontSize:11}, height:'auto' }); win1.add(hoeveel); firstNameField.value = Ti.App.Properties.getString('username'); lastNameField.value = Ti.App.Properties.getString('password'); // // CREATE BUTTON // if (language=='nl') { var ditsaven = Titanium.UI.createButton({ title:'Gegevens updaten', top:200, left:30, height:30, width:250 }); } else { var ditsaven = Titanium.UI.createButton({ title:'Update Settings', top:200, left:30, height:30, width:250 }); } ditsaven.addEventListener('click', function(e){ Ti.API.info('event dit saven'); Tools.setNaam('dit'); }); win1.add(ditsaven); // // CREATE INFO MESSAGE // var messageView = Titanium.UI.createView({ bottom:10, backgroundColor:'#111', height:40, width:270, borderRadius:10 }); if (language=='nl') { var messageLabel = Titanium.UI.createLabel({ color:'#fff', text:'Welkom! Vul je login gegevens in.', height:'auto', width:'auto', textAlign:'center' }); } else { var messageLabel = Titanium.UI.createLabel({ color:'#fff', text:'Welcome! Fillin your login info.', height:'auto', width:'auto', textAlign:'center' }); } messageView.add(messageLabel); win1.add(messageView); return win1; }
2 Answers
Accepted Answer
You'll need to expose the actiefzijn variable somehow in your IndexView.js module:
module.exports = function() { var win1 = Ti.UI.createView($$.FULL_SCREEN); var actiefzijn = Titanium.UI.createLabel({...}); ... win1.xgetActiefzijn = function () { return actiefzijn; } return win1; }Notice that I didn't call the function
getActiefzijn, but I put an "x" in front of the name. You don't want to name any methods starting with "get" or "set".
When you need to access this label from outside the module, you can do this:
var iv = new IndexView(); ... var actiefzijn = iv.xgetActiefzijn ();You may be interested in these articles that cover classical OO design with CommonJS and using CommonJS with Titanium.
not working completely yet, getting closer do. i might have to ket the function handle the change instead of doing it remotely?
function in tools
exports.setNaam = function(args) { var Mods = require('/ModulePaths'); var IndexView = require(Mods.INDEXVIEW); var iv = new IndexView(); var actiefzijn = iv.xgetActiefzijn() ; Ti.API.info('in setnaam'); actiefzijn.text='veranderd in setnaam'; }
Your Answer
Think you can help? Login to answer this question!