Skip to content

Commit

Permalink
made some improvements to the form(JSON) like adding validations and …
Browse files Browse the repository at this point in the history
…error infos
  • Loading branch information
railsfactory-magesh committed Jan 24, 2011
1 parent 3d8a024 commit 45c57e3
Show file tree
Hide file tree
Showing 5 changed files with 781 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Resources/app.js
Expand Up @@ -16,7 +16,7 @@ var tab1 = Titanium.UI.createTab({

var data = [
{title:'Form', hasChild:true, test:'forms.js'},
{title:'Facebook', hasChild:true},
{title:'Linkification', hasChild:true, test:'link.js'},
{title:'GeexHQ', hasChild:true, test:'geexhq.js'},
{title:'Fibonacci', hasChild:true, test:'fibonacci.js'},
{title:'Calculator', hasChild:true, test:'calc.js'}
Expand Down
101 changes: 80 additions & 21 deletions Resources/forms.js
Expand Up @@ -8,7 +8,7 @@ var nameLabel = Titanium.UI.createLabel({
fontSize:15
},
textAlign:'center',
top:10,
top:5,
width:300,
height:'auto'
});
Expand All @@ -17,10 +17,13 @@ win.add(nameLabel);
var nameField = Titanium.UI.createTextField({
color:'#336699',
height:45,
top:50,
top:30,
left:40,
width:250,
borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
borderRadius:5,
borderWidth:2,
borderColor:'#999',
// borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(nameField);

Expand All @@ -32,14 +35,47 @@ var titleLabel = Titanium.UI.createLabel({
fontSize:15
},
textAlign:'center',
top:20,
top:80,
width:300,
height:'auto'
});
win.add(titleLabel);


var titleField = Titanium.UI.createTextField({
color:'#336699',
height:45,
top:110,
left:40,
width:250,
borderRadius:5,
borderWidth:2,
borderColor:'#999'
// borderStyle:Titanium.UI.INPUT_BORDERSTYLE_ROUNDED
});
win.add(titleField);

var bodyLabel = Titanium.UI.createLabel({
text:'Content',
color:'#777',
font:{
fontFamily:'Helvetica Neue',
fontSize:15
},
textAlign:'center',
top:150,
width:300,
height:'auto'
});
win.add(bodyLabel);


var bodyField = Ti.UI.createTextArea({borderRadius:5,borderWidth:2,borderColor:'#999',bottom:50,left:30,right:30,height:100,top:170, font:{fontFamily:'courier',fontSize:10}});
win.add(bodyField);


var blurButton = Titanium.UI.createButton({
top:100,
bottom:10,
height:40,
width:100,
title:'Submit'
Expand All @@ -50,27 +86,50 @@ blurButton.addEventListener('click', function()
send();
});

var xhr = Ti.Network.createHTTPClient();

function send()
{
var name = nameField.value;
// var title = document.getElementById('title').value;
// var content = document.getElementById('content').value;
Ti.API.info("clicked on send button");
Ti.API.info(name);
alert(name);
var title = titleField.value;
var content = bodyField.value;

if(title && content != null){



Ti.API.info("clicked on send button");
Ti.API.info("Name: " + name + "title: " + title + "body: " + content );


xhr.open("POST","http://192.168.1.175:3000/posts");
var params = {
name:name,
title:title,
content:content
}

var request = Ti.Network.createHTTPClient();
Ti.API.info(params);

xhr.send(params);
}else
{
alert("Please Enter the needed infos");
}

request.open("POST","http://192.168.1.175:3000/posts");
var params = {
name:name,
title:"this is the title",
content:"this is the content"
}
// var data = JSON.stringify(params);
Ti.API.info(params);
// Ti.API.info(data);
request.send(params);
};

xhr.onerror = function(e) {

var a = Titanium.UI.createAlertDialog({
title:'Well, this is awkward...',
message: 'We had a problem posting your blogpost - please try again'
});
a.show();
alert(e.error);
};

xhr.onload = function(data) {
var data = JSON.parse(data);
Ti.API.info(data);
};
2 changes: 1 addition & 1 deletion Resources/link.js
@@ -1,7 +1,7 @@
var win = Ti.UI.currentWindow;

var numberLabel = Titanium.UI.createLabel({
text: 'Contact Magesh\n magesh@geexhq.com\n http://railsfactory.com\n 9940305209\n Chennai, Tamil Nadu, India',
text: 'Contact Magesh\n magesh@geexhq.com\n http://railsfactory.com\n 9940305209\n RailsFactory Chennai, Tamil Nadu, India',
color:'#777',
font:{
fontFamily:'Helvetica Neue',
Expand Down

0 comments on commit 45c57e3

Please sign in to comment.