Good morning, I have a question concerning values of textfields. In an app I wrote, I have a textfield and a button; when the button is clicked, the program should get the value of the textfield, which the user set previously. Then I want to include this value in an e-mail. However, it doesn't work, the mail prints out all other variables perfectly, except for the value of the textfield. In the following, I included the necessary code:
var Eingabefeld = Titanium.UI.createTextField({ clearOnEdit : false, backgroundGradient : { type : 'linear', colors : ['#DCDCDC', '#FFF'], startPoint : { x : 0, y : 0 }, endPoint : { x : 0, y : 50 }, backFillStart : false }, color : '#350062', font : { fontSize : 24, fontFamily : 'Helvetica Neue' }, borderColor : '#350062', top : 170, width : 290, height : 30 }); var Button = Titanium.UI.createButton({ title : 'Read Later', style : Titanium.UI.iPhone.SystemButtonStyle.PLAIN, backgroundGradient : { type : 'linear', colors : ['#6F00CE', '#350062'], startPoint : { x : 0, y : 0 }, endPoint : { x : 0, y : 50 }, backFillStart : false }, borderRadius : 20, top : 220, width : 300, height : 40 }); Button.addEventListener('click', function(e) { emailDialog.open() }); var currentTime = new Date(); var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() var emailDialog = Titanium.UI.createEmailDialog( { subject: 'Test ' + month + '/' + day + '/' + year, toRecipients: ['justin.rennert12@googlemail.com'], messageBody: 'This is a test for the ' + day + 'th of ' + month + ' ' + year + ': ' + Eingabefeld.value + 'Check back tomorrow!' }); Win1.add(TitleLabel); Win1.add(Eingabefeld); Win1.add(Button); Win1.open();
2 Answers
Accepted Answer
You should create the email dialog window inside the click event.
The code could go something like this:Button.addEventListener('click', function(e) {
var emailDialog = Titanium.UI.createEmailDialog( {
subject: 'Test ' + month + '/' + day + '/' + year,
toRecipients: ['justin.rennert12@googlemail.com'],
messageBody: 'This is a test for the ' + day + 'th of ' + month + ' ' + year + ': ' + Eingabefeld.getValue() + 'Check back tomorrow!'
});
emailDialog.open()
});
I also suggest that you use the getValue() funciton instead of the value property.
You're creating the dialog before the window is even open, at which time, the value of the text field is an empty string. Create it when the user clicks the button so you can use the current value of the text field. Try creating your EmailDialog inside of your button's click event listener.
Your Answer
This question has been locked and cannot accept new answers.