0 Replies - 2280 Views - Last Post: 21 October 2013 - 06:40 PM

#1 rollinhard  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 67
  • Joined: 13-February 05

Titanium Appcelerator - Loop/If

Posted 21 October 2013 - 06:40 PM

Not sure if anyone here uses Titanium, but I'm running into a coding issue. I'm developing this for a class that I'm in. I'm trying to work through it logically, but I'm at a block.
What I'm wanting to do on the profiles page - Add a "Add Pet" button that when clicked will display the form that's currently there. Once the form is filled out the info will be submitted, the text displayed will change from "add pet" to the pet's name, add the "Add Pet" button will be placed under the old button.

I know it's going to look something like

If AddPetButton is clicked
add labels and textfields to profilePageView
on submit addPetButton name = PetName
addPetButton

I know I'll need a loop to control the change of previous field names to increase the iteration but I'm drawing a blank.
Any help is appreciated.

This is my current code if you want to view the app.
//Creating all windows
//Main, Panic, Profile
var MainWindow = Ti.UI.createWindow({
	backgroundColor: 'D2B48C'
});

var PanicWindow = Ti.UI.createWindow({
	name: 'PanicWindow',
	backgroundColor: 'F0E68C'
});

var ProfileWindow = Ti.UI.createWindow({
	name: 'ProfileWindow',
	backgroundColor: '778899'
});


//Creating all views
//Scroll view to be added to Profile Page
 
var viewMainWindow = Ti.UI.createView();
var viewPanicWindow = Ti.UI.createView();
var viewProfileWindow = Ti.UI.createScrollView({
	contentWidth: 'auto',
    contentHeight: 'auto',
    top: 0,
    bottom: 0,
    showVerticalScrollIndicator: true,
    showHorizontalScrollIndicator: true
});

//Creating label place holder for logo in center screen
var PetRescue = Ti.UI.createLabel({
	name: 'PetRescue',
	text: 'Pet Rescue',
	height: 'auto',
	top: 100,
	width: 'auto'
});

//Panic Button: On click goes to Panic Window
var PanicButton = Ti.UI.createButton({
	name: 'PanicButton',
	Color: 'red',
	font: {
		fontFamily : 'Arial',
		fontSize : '25',
		fontWeight : 'bold',
		},
	height : '15%',
	left : '60',
	title : 'Panic Button',
	top : '330',
	width : '63%',
});
PanicButton.addEventListener('click', function(e){
	Panicwindow.open({
		transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT
	});
	Ti.API.info("Panic Button was Clicked");
});


//Profile Button: On click goes to Profile Window
var ProfilesButton = Ti.UI.createButton({
	name : 'Profiles',
	font : {
		fontFamily : 'Arial',
		fontSize : '10',
		},
	height: 'auto',
	left: '4%',
	title: 'Profiles',
	top: '4%',
	width: 'auto',
});
ProfilesButton.addEventListener('click', function(e){
	Profilewindow.open({
		transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT
	});
	Ti.API.info("Profile Button was Clicked");
});


//ReturnButton closes Panic Window and returns to Main Window
var Return = Ti.UI.createButton({
	font: {
		fontFamily : 'Arial',
		fontSize : '10',
		},
		height: 'auto',
		width: 'auto',
		title: 'Home',
		top: '4%',
		right: '4%',
});
Return.addEventListener('click', function(e){
	Panicwindow.close({
		transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
	});
	Ti.API.info("Return from Panic Button was Clicked");
});

//Return2: Returns form Profile Page to Main Window
var Return2 = Ti.UI.createButton({
	font: {
		fontFamily : 'Arial',
		fontSize : '10',
		},
		height: 'auto',
		width: 'auto',
		title: 'Home',
		top: '4%',
		right: '4%',
});
Return2.addEventListener('click', function(e){
	Profilewindow.close({
		transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
	});
	Ti.API.info("Return from Profile Button was Clicked");
});


//FORM FOR PET PROFILE
//Creating the form to create the Pet Profile
var PetName = Ti.UI.createLabel({
	color:'black',
    text:"Pet Name",
    top:10,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto'
});

var PetNameField = Titanium.UI.createTextField({
    hintText:'Enter Pet Name',
    top:30,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto',
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});


var RecentImage = Ti.UI.createLabel({
	color:'black',
    text:"Recent Photo",
    top:70,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto'
});

//NEED TO ADD FUNCTION TO USE CAMERA TO TAKE A CURRENT PHOTO


var MicrochipInfo = Ti.UI.createLabel({
	color:'black',
    text:"Microchip Information",
    top:200,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto'
});

var MicrochipInfoField = Titanium.UI.createTextField({
    hintText:'Enter Microchip Number',
    top:220,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto',
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});

var OwnerName = Ti.UI.createLabel({
	color:'black',
    text:"Owner Name",
    top:260,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto'
});

var OwnerNameField = Titanium.UI.createTextField({
    hintText:'Enter Owner Name',
    top:280,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto',
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});

var OwnerPhone = Ti.UI.createLabel({
	color:'black',
    text:"Owner Phone Number",
    top:320,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto'
});

var OwnerPhoneField = Titanium.UI.createTextField({
    hintText:'Enter Owner Phone Number',
    top:350,
    left:10,
    width:200,
    font:{fontSize:15,fontFamily:'Helvetica Neue'},
    height:'auto',
    borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});

//Submit Button for Pet Profile Form
//               NEEDS TO GET ALL INFO THAT HAS BEEN SUBMITTED
var ProfileSubmit = Ti.UI.createButton({
	title: 'Submit',
	top: 420,
	width: 150,
	height: 30,
});
ProfileSubmit.addEventListener('click', function(e){
	alert(PetNameField.getValue());
});



//Adding Buttons and Label to views for main window
viewMainwindow.add(PetRescue);
viewMainwindow.add (PanicButton);
viewMainwindow.add (ProfilesButton);
Mainwindow.add(viewMainWindow);


//Profile Window should have ability to add a pet profile
viewProfilewindow.add(Return2);
viewProfilewindow.add(PetName);
viewProfilewindow.add(PetNameField);
viewProfilewindow.add(RecentImage);
viewProfilewindow.add(MicrochipInfo);
viewProfilewindow.add(MicrochipInfoField);
viewProfilewindow.add(OwnerName);
viewProfilewindow.add(OwnerNameField);
viewProfilewindow.add(OwnerPhone);
viewProfilewindow.add(OwnerPhoneField);
viewProfilewindow.add(ProfileSubmit);
Profilewindow.add(viewProfileWindow);


//Add views to PanicWindow
viewPanicwindow.add(PetRescue);
viewPanicwindow.add(Return);
Panicwindow.add(viewPanicWindow);


Mainwindow.open();




This post has been edited by rollinhard: 21 October 2013 - 06:42 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1