Multiple text entry problem with windows,tables and buttons?

You must Login before you can answer or comment on any questions.

I would like to enter a text into a textfield and when i press a button on the same window a new window opens with a tableview and another button. When pressed to the tableview, you can see the value entered to the textfield. When pressed to the button you will return to the first window where you enter a text to enter a new text. So it's like a cycle. My problem is, when i click to the second button and enter another text, and go to the tableview to see the texts i see the second text at both tableviewrows. I appreciate your help.

— asked 10 months ago by Solen Hedili
4 Comments
  • Hi Solen

    You really need to provide some code so that we can try it, see what happens, hopefully work out what went wrong and give you some pointers.

    I look forward to seeing some code.

    People here are smart - but very few are mind-readers :)

    — commented 10 months ago by Malcolm Hollingsworth

  • I hope I didn't make it more diffucult to understand.

    — commented 10 months ago by Solen Hedili

  • Hi Soleen

    I know you just sent me a direct email with code but you need to put it up in this question.

    I am not the only one able to help you and if someone else pops their head into this question and sees your code - works out the problem straight away then you have your answer. Plus this is for the benefit of the community - so they should benefit from seeing how a problem is resolved (hopefully) through from start to finish.

    Plus the DevLink system cut the code off part-way through as it has a limit.

    — commented 10 months ago by Malcolm Hollingsworth

  • Show 1 more comment

5 Answers

var totalperson = 0;
var window = Ti.UI.createWindow({
backgroundColor:'white' });

var text = Titanium.UI.createTextField({
top:10,
left:100,
width:300,
hintText:'Enter name',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
window.add(classes);

var Button = Titanium.UI.createButton({
title:'OK', top:250,
left:175,
width:140,
font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
}); window.add(Button);

Button.addEventListener('click',function(e){
totalperson++;
var newwindow = Ti.UI.createWindow({
backgroundColor:'white' }); data=[];
data[0]= Ti.UI.createTableViewRow({title:'view names',hasChild:true});
var newtable = Ti.UI.createTableView({
data:data
}); newwindow.add(newtable);
var newbutton = Titanium.UI.createButton({
title:('add new class')
}); newwindow.add(newbutton);

newbutton.addEventListener('click', function(e){
newwindow.close();
text.value='';
});

newtable.addEventListener('click',function(e){
var people = [];
people[0] = Ti.UI.createTableViewRow({title:'people',hasChild:true});

var newerwindow = Ti.UI.createWindow({
backgroundColor:'white'
}); var newertable = Ti.UI.createTableView({
data:people

}); newerwindow.add(newertable);

people[0].addEventListener('click',function(e){

var newestwindow = Ti.UI.createWindow({
backgroundColor:'white'
});
y=[];
for(var i=0;i<totalperson;i++){
y[i]=Ti.UI.createTableViewRow({title:classes.value + ' ' + time.value});
}
var bigtable = Ti.UI.createTableView({
data:y
}); newestwindow.add(bigtable); }
});

It is something like this. Don't worry about the navigation. When I run the true version when I press "newbutton" and type a new text and want to view it it shows the second text at the last tableview

— answered 10 months ago by Solen Hedili
answer permalink
1 Comment
  • Tidied version for the benefit of all - who may help.

    var totalperson = 0;
    var window = Ti.UI.createWindow({
        backgroundColor: 'white'
    });
     
    var text = Titanium.UI.createTextField({
        top: 10,
        left: 100,
        width: 300,
        hintText: 'Enter name',
        keyboardType: Titanium.UI.KEYBOARD_DEFAULT,
        returnKeyType: Titanium.UI.RETURNKEY_DEFAULT,
        borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
    });
    window.add(classes);
     
    var Button = Titanium.UI.createButton({
        title: 'OK',
        top: 250,
        left: 175,
        width: 140,
        font: {
            fontFamily: 'Arial',
            fontWeight: 'bold',
            fontSize: 14
        }
    });
    window.add(Button);
     
    Button.addEventListener('click', function (e) {
        totalperson++;
        var newwindow = Ti.UI.createWindow({
            backgroundColor: 'white'
        });
        data = [];
        data[0] = Ti.UI.createTableViewRow({
            title: 'view names',
            hasChild: true
        });
        var newtable = Ti.UI.createTableView({
            data: data
        });
        newwindow.add(newtable);
        var newbutton = Titanium.UI.createButton({
            title: ('add new class')
        });
        newwindow.add(newbutton);
     
        newbutton.addEventListener('click', function (e) {
            newwindow.close();
            text.value = '';
        });
     
        newtable.addEventListener('click', function (e) {
            var people = [];
            people[0] = Ti.UI.createTableViewRow({
                title: 'people',
                hasChild: true
            });
     
            var newerwindow = Ti.UI.createWindow({
                backgroundColor: 'white'
            });
            var newertable = Ti.UI.createTableView({
                data: people
     
            });
            newerwindow.add(newertable);
     
            people[0].addEventListener('click', function (e) {
     
                var newestwindow = Ti.UI.createWindow({
                    backgroundColor: 'white'
                });
                y = [];
                for (var i = 0; i < totalperson; i++) {
                    y[i] = Ti.UI.createTableViewRow({
                        title: classes.value + ' ' + time.value
                    });
                }
                var bigtable = Ti.UI.createTableView({
                    data: y
                });
                newestwindow.add(bigtable);
            }
            });

    — commented 10 months ago by Malcolm Hollingsworth

Hi Solen

Cheers for this - quick tip though add three ~ above the first line of code and three more ~ below the last line. It styles the code and makes it easier to work out. I have cleaned you code and put it at as a comment on your question - top help others.

Before we start can you confirm the first block of code for me as it appears to start of with an error straight away.

You add a textfield called text, but you yo never add it to the window - instead you add something called classes

var text = Titanium.UI.createTextField({
    top: 10,
    left: 100,
    width: 300,
    hintText: 'Enter name',
    keyboardType: Titanium.UI.KEYBOARD_DEFAULT,
    returnKeyType: Titanium.UI.RETURNKEY_DEFAULT,
    borderStyle: Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
window.add(classes);  // so why add something called classes
Further into your code you reference both text and classes.

Can you review this and amend as required. I suspect the problem may relate to this issue, and if not it would be good to have the code fixed before we review it.

— answered 10 months ago by Malcolm Hollingsworth
answer permalink
6 Comments
  • Hi Malcolm, what I want to to for real is to make a school schedule, i would like to add a class, then say ok, then with a button, I will return to that window where i enter the class name, time day. Because there are many variables, I just said classes to be names, I copy pasted some of my code and I forgot to change some names. But did you understand what I'm trying to do? When I add the second class, when I go to view it, there is the second class at both tableview rows.

    — commented 10 months ago by Solen Hedili

  • I think the error is newbutton.addEventListener('click', function (e) { newwindow.close(); text.value = ''; });

    or for (var i = 0; i < totalperson; i++) { y[i] = Ti.UI.createTableViewRow({ title: classes.value + ' ' + time.value }); } Can you look at these?

    — commented 10 months ago by Solen Hedili

  • That text is actually classes.I just changed it's name with hand, you made me realized I didn't changed it everywhere.

    — commented 10 months ago by Solen Hedili

  • Show 3 more comments

// Flags, is this for Android or iPhone? var iPhone = false; var Android = false; if(Ti.Platform.osname == 'iphone'){ iPhone = true }; if(Ti.Platform.osname == 'android'){ Android = true };

// our navigation function, to be compatible with both platforms function NavigationController(a){ // this is to avoid errors a = a || {}; a.window = a.window || Ti.UI.createWindow(); // this is to handle the iPhone Nav functionality if(iPhone){ var win = Ti.UI.createWindow(); var nav = Ti.UI.iPhone.createNavigationGroup({ window: a.window }); win.add(nav); win.push = function(e){ nav.open(e); }; return win; } // there is no Nav in Android, so let's return the window if(Android){ a.window.push = function(e){ e.open({ fullscreen:false }); } return a.window; } }

var mondaycourse = 0; var tuesdaycourse = 0; var wednesdaycourse = 0; var thursdaycourse = 0; var fridaycourse = 0; var classnumber = mondaycourse + tuesdaycourse + wednesdaycourse + thursdaycourse + fridaycourse; // start the app right here var win = Ti.UI.createWindow({ backgroundColor:'white' }); var data = [];

data[0] = Ti.UI.createTableViewRow({hasChild:true,title:'Schedules'});

var table = Ti.UI.createTableView({ data:data
}); win.add(table);

// let's call our custom navigation function var navigation = NavigationController({ window:win }); // open it navigation.open(); data[0].addEventListener('click',function(){

var win2 = Ti.UI.createWindow({
    backgroundColor:'white'
});
var data2=[];

data2[0] = Ti.UI.createTableViewRow({hasChild:true,title:'New Schedules'});
var table2 = Ti.UI.createTableView({
    data:data2
});
win2.add(table2);
navigation.push(win2);
data2[0].addEventListener('click',function(){
    var win3 = Ti.UI.createWindow({
        backgroundColor:'white'
    });


var classes = Titanium.UI.createTextField({  
color:'#336699', 
top:10,  
left:100,
width:300,
hintText:'Enter class name',  
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,  
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,  
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED  

});
win3.add(classes);

var days = Titanium.UI.createTextField({
color:'#336699', top:80,
left:100, width:300, hintText:'Enter day',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win3.add(days);

var time = Titanium.UI.createTextField({
color:'#336699', top:150,
left:100, width:300, hintText:'Enter time period',
keyboardType:Titanium.UI.KEYBOARD_DEFAULT,
returnKeyType:Titanium.UI.RETURNKEY_DEFAULT,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win3.add(time);
var Button = Titanium.UI.createButton({
title:'OK', top:250, left:175, width:140, font:{fontFamily:'Arial',fontWeight:'bold',fontSize:14}
}); win3.add(Button); navigation.push(win3);

Button.addEventListener('click',function(e){ if(classes.value != '' && days.value != '' && time.value != ''){ classnumber++; var newwindow = Ti.UI.createWindow({ backgroundColor:'white' }); include=[]; include[0]= Ti.UI.createTableViewRow({title:'view current schedule',hasChild:true}); var newtable = Ti.UI.createTableView({ data:include }); newwindow.add(newtable); var newbutton = Titanium.UI.createButton({ title:('add new class') }); newwindow.add(newbutton);

navigation.push(newwindow);
var monday = 'monday';
var tuesday = 'tuesday';
var wednesday = 'wednesday';
var thursday = 'thursday';
var friday = 'friday';
if(days.value == monday){
    mondaycourse++;
}
else if(days.value == tuesday){
    tuesdaycourse++;
}
else if(days.value == wednesday){
    wednesdaycourse++;
}
else if(days.value == thursday){
    thursdaycourse++;
}
else if(days.value == friday){
    fridaycourse++;
}
y=[];

for(var x=0; x&lt;classnumber;x++){
    y[x]=Ti.UI.createTableViewRow({title:classes.value + '      ' + time.value});
}

newbutton.addEventListener('click', function(e){
    newwindow.close();
});


newtable.addEventListener('click',function(e){
var dayofweek = [];
    dayofweek[0] = Ti.UI.createTableViewRow({title:'Monday',hasChild:true});
    dayofweek[1] = Ti.UI.createTableViewRow({title:'Tuesday',hasChild:true});
    dayofweek[2] = Ti.UI.createTableViewRow({title:'Wednesday',hasChild:true});
    dayofweek[3] = Ti.UI.createTableViewRow({title:'Thursday',hasChild:true});
    dayofweek[4] = Ti.UI.createTableViewRow({title:'Friday',hasChild:true});
    var newerwindow = Ti.UI.createWindow({
        backgroundColor:'white'
});
var newertable = Ti.UI.createTableView({
    data:dayofweek

}); newerwindow.add(newertable); navigation.push(newerwindow);

dayofweek[0].addEventListener('click',function(e){

var newestwindow = Ti.UI.createWindow({
        backgroundColor:'white'
    });     
    if(days.value == monday){
        for(var n=0;n&lt;mondaycourse;n++){
            y[n]=Ti.UI.createTableViewRow({title:classes.value + '      ' + time.value});
        }
        var bigtable = Ti.UI.createTableView({
            data:y
    });
    newestwindow.add(bigtable);
    }
    navigation.push(newestwindow);

});

dayofweek[1].addEventListener('click',function(e){

    var b=[];
    for(var j=0;j&lt;tuesdaycourse;j++){
        b[j] = Ti.UI.createTableViewRow({title: classes.value + '   ' + time.value});
    }
    var newestttable = Ti.UI.createTableView({
        data:b
    });
    var newesttwindow = Ti.UI.createWindow({
        backgroundColor:'white'
    });
    newesttwindow.add(newestttable);
    navigation.push(newesttwindow);
});

dayofweek[2].addEventListener('click',function(e){

    var c=[];
    for(var k=0; k&lt;wednesdaycourse; k++){
        c[k] = Ti.UI.createTableViewRow({title: classes.value + '   ' + time.value});
    }
    var newesttttable = Ti.UI.createTableView({
        data:c
    });
    var newestttwindow = Ti.UI.createWindow({
        backgroundColor:'white'
    });
    newestttwindow.add(newesttttable);
    navigation.push(newestttwindow);

}); dayofweek[3].addEventListener('click',function(e){

    var d=[];
    for(var l=0;l&lt;thursdaycourse;l++){
        d[l] = Ti.UI.createTableViewRow({title: classes.value + '   ' + time.value});
    }
    var newestttttable = Ti.UI.createTableView({
        data:d
    });
    var newesttttwindow = Ti.UI.createWindow({
        backgroundColor:'white'
    });
    newesttttwindow.add(newestttttable);
    navigation.push(newesttttwindow);

}); dayofweek[4].addEventListener('click',function(e){

    var e=[];
    for (var m=0;m&lt;fridaycourse;m++){
        e[m] = Ti.UI.createTableViewRow({title: classes.value + '   ' + time.value});
    }
    var newesttttttable = Ti.UI.createTableView({
        data:e
    });
    var newesttttttwindow = Ti.UI.createWindow({
        backgroundColor:'white'
    });
    newesttttttwindow.add(newesttttttable);
    navigation.push(newesttttttwindow);

});

}); }//if için

else{ alert('Fill the missing data!!!');
} });

}); });

— answered 10 months ago by Solen Hedili
answer permalink
11 Comments
  • ~ didn't work. I think it's because it's too long

    — commented 10 months ago by Solen Hedili

  • I'm sorry for the bad programming skills and the awful variable names.

    — commented 10 months ago by Solen Hedili

  • Hi Solen

    You HAVE to post code - especially this long correctly. This is un-readble.

    Please repost the code but add three ~ symbols on a line on their own above the first line of code, and then again three ~ underneath the last line of code.

    If you are not sure - press the Code button in the text editor you pasted the code into - it explains it there.

    — commented 10 months ago by Malcolm Hollingsworth

  • Show 8 more comments

dayofweek[0].addEventListener('click',function(e){
 
    var newestwindow = Ti.UI.createWindow({
            backgroundColor:'white'
        });     
        if(days.value == monday){
            for(var n=0;n<mondaycourse;n++){
                y[n]=Ti.UI.createTableViewRow({title:classes.value + '      ' + time.value});
            }
            var bigtable = Ti.UI.createTableView({
                data:y
        });
        newestwindow.add(bigtable);
        }
        navigation.push(newestwindow);
 
});
 
dayofweek[1].addEventListener('click',function(e){
 
        var b=[];
        for(var j=0;j<tuesdaycourse;j++){
            b[j] = Ti.UI.createTableViewRow({title: classes.value + '   ' + time.value});
        }
        var newestttable = Ti.UI.createTableView({
            data:b
        });
        var newesttwindow = Ti.UI.createWindow({
            backgroundColor:'white'
        });
        newesttwindow.add(newestttable);
        navigation.push(newesttwindow);
    });
dayofweek[2].addEventListener('click',function(e){
 
        var c=[];
        for(var k=0; k<wednesdaycourse; k++){
            c[k] = Ti.UI.createTableViewRow({title: classes.value + '   ' + time.value});
        }
        var newesttttable = Ti.UI.createTableView({
            data:c
        });
        var newestttwindow = Ti.UI.createWindow({
            backgroundColor:'white'
        });
        newestttwindow.add(newesttttable);
        navigation.push(newestttwindow);
});
dayofweek[3].addEventListener('click',function(e){
 
        var d=[];
        for(var l=0;l<thursdaycourse;l++){
            d[l] = Ti.UI.createTableViewRow({title: classes.value + '   ' + time.value});
        }
        var newestttttable = Ti.UI.createTableView({
            data:d
        });
        var newesttttwindow = Ti.UI.createWindow({
            backgroundColor:'white'
        });
        newesttttwindow.add(newestttttable);
        navigation.push(newesttttwindow);
});
dayofweek[4].addEventListener('click',function(e){
 
        var e=[];
        for (var m=0;m<fridaycourse;m++){
            e[m] = Ti.UI.createTableViewRow({title: classes.value + '   ' + time.value});
        }
        var newesttttttable = Ti.UI.createTableView({
            data:e
        });
        var newesttttttwindow = Ti.UI.createWindow({
            backgroundColor:'white'
        });
        newesttttttwindow.add(newesttttttable);
        navigation.push(newesttttttwindow);
 
});
 
});
}//if için
 
else{
        alert('Fill the missing data!!!');  
    }
});
 
});
});

— answered 10 months ago by Solen Hedili
answer permalink
3 Comments
  • That's it.

    — commented 10 months ago by Solen Hedili

  • I have got the code now.

    I cannot review it right now as I should have been working for the last couple of hours. But this evening I will go through and see what can bee seen. I will then report back.

    I can say that your code can be simplified as your row event listeners for each table can be collapsed into a single handlers. I will show you how later on.

    Right now be patient - I will be back.

    — commented 10 months ago by Malcolm Hollingsworth

  • Ok thank you very much, I'm looking forward for your guidance

    — commented 10 months ago by Solen Hedili

Hi Solen

Reading your code I am getting stuck with your nav controller. Can you tell me what you are doing with the push lines as far as I can see these are not valid commands from the createWindow event and not the correct syntax for javascript either.

function NavigationController(a) {
    // this is to avoid errors
    a = a || {};
    a.window = a.window || Ti.UI.createWindow();
    // this is to handle the iPhone Nav functionality
    if (iPhone) {
        var win = Ti.UI.createWindow();
        var nav = Ti.UI.iPhone.createNavigationGroup({
            window: a.window
        });
        win.add(nav);
        win.push = function (e) {  // problem starts here for iOS
            nav.open(e);
        };
        return win;
    }
    // there is no Nav in Android, so let's return the window
    if (Android) {
        a.window.push = function (e) { // problem starts here for iOS
            e.open({
                fullscreen: false
            });
        }
        return a.window;
    }
}
Push would normally follow this syntax, when applied to an array;
arrayExample.push(newArrayElement);
Let me know.

Also - does ANY of this code actually work as I cannot get the app to even run using the code supplied.

— answered 10 months ago by Malcolm Hollingsworth
answer permalink
3 Comments
  • Hi Malcolm, I believe that navigation controller lets you switch between windows, I think if you erase them and just say open(window) it will be the same. This code works in my computer but don't worry about the beginning, where you should consider mostly is when you type the classes, days and time. I can not save the first entries when i enter the second one. That's my major problem.

    — commented 10 months ago by Solen Hedili

  • Hi Solen

    Can you give me a simple step by step as I still do not understand what you are trying to achieve.

    This is what I THINK you mean in your layout - but still not sure.

    • Window 1: Contains a textfield and button, click the button and it opens the second window
    • Window 2: Tableview and button
    • Window 3: Label (displaying the value from first window) and button

    What I cannot work out is if you want the window 3 button to cause 'window 3' and 'window 2' to close automatically or not?

    You end by saying two tableviews but only one appears in your description.

    I am trying to help you but without example code that can be run, your push lines stop the code running at all. I also need a clearer description, tell me which window things appear and exactly what you are hoping should happen.

    Use paragraphs and clearly describe what things appear on what windows.

    — commented 10 months ago by Malcolm Hollingsworth

  • Ok, the first and second part of the three item is correct. When you press the tableview, you will enter the third window and can see the results. When you click the button on the second window, you will go back to the first window where you enter another text. When i enter a text for the first time everything is good, but when i press to the button and enter another text and open the tableview, i see the second entry at both tableview rows.

    — commented 10 months ago by Solen Hedili

Your Answer

Think you can help? Login to answer this question!