I have been searching and trying different stuff for 1 1/2 days but can seem to figure out how to get populate this form using json. Ive probably seen about 20 different ways to do it but just can get it to work. Thanks in advance for any help.
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = "side";
var userProfileForm = new Ext.form.FormPanel({
name: 'userProfileForm',
renderTo:"UserInfoForm",
width:470,
labelWidth:160,
frame:true,
monitorValid:true,
items: [
new Ext.form.Hidden({
name: "user_id"
}),
new Ext.form.TextField({
name:"first_nm",
fieldLabel:"First Name",
width:265,
allowBlank:false,
blankText:"Please enter a First Name"
}),
new Ext.form.TextField({
name:"last_nm",
fieldLabel:"Last Name",
width:265,
allowBlank:false,
blankText:"Please enter a Last Name"
}),
new Ext.form.TextField({
name:"mlsAgent_id",
fieldLabel:"MLS Agent ID",
width:265,
allowBlank:true
}),
new Ext.form.TextField({
id:"team_id",
fieldLabel:"Team ID",
width:265,
allowBlank:true
}),
new Ext.form.TextField({
name:"email_txt",
fieldLabel:"Email Address",
width:265,
allowBlank:false,
blankText:"Please enter an Email Address",
vtype:"email",
vtypeText:"Enter a valid Email Address"
}),
new Ext.form.TextField({
name:"title_txt",
fieldLabel:"Title",
width:265,
allowBlank:true
}),
new Ext.form.TextField({
name:"phone_no",
fieldLabel:"Phone No",
width:265,
allowBlank:true
}),
new Ext.form.TextField({
name:"mobile_no",
fieldLabel:"Mobile No",
width:265,
allowBlank:true
}),
new Ext.form.TextField({
name:"fax_no",
fieldLabel:"Fax No",
width:265,
allowBlank:true
}),
new Ext.form.TextField({
name:"website_url",
fieldLabel:"Personal Website",
width:265,
allowBlank:true
})
]
buttons:[{
text:'Update Information',
formBind: true,
// Function that fires when user clicks the button
handler:function(){
userProfileForm.getForm().submit({
method:'POST',
waitTitle:'Saving Information',
waitMsg:'Sending data...',
url: '/api/user-save/type/profile/',
success:function(){
Ext.Msg.alert('Status', 'Save Successful!', function(btn, text){
if (btn == 'ok'){
}
});
},
failure:function(form, action){
if(action.failureType == 'server'){
Ext.Msg.alert('Save Failed! Please try again.');
}else {
Ext.Msg.alert('Warning!', 'Server is unreachable');
}
}
});
}
}]
})
userProfileForm.getForm().load({url:"/api/userinfo", waitMsg:"Loading User Data"});
JSON (verified using jslint)
{"success":true,"data":{"first_nm":"Mike","last_nm":"Camire","mlsAgent_Id":"645872","email_txt":"mcamire1@yahoo.com","title_txt":"Realtor"
,"phone_no":"000-000-0000","mobile_no":"","fax_no":"","website_url":"http://www.devonshirehomes.com"}}
All the fields and the json return look right. I am assuming you are not doing the load until after the form is rendered. I don't know if having that reader attribute on the form would interfere with the ajax load. I would just step through it all in the firebug debugger, including the load success handler.
Man I didnt see that I had left that reader in there. Guess thats what happens when you stare at the code too long. Thanks, I got it working.
Obvious questions, have you verified you are getting the JSON string back in your success handler? I use a similar format - although I always set both success and failure attributes, but I don't think that is necessary.
Yea that is the json string that is coming back in firebug.
Obvious questions, have you verified you are getting the JSON string back in your success handler? I use a similar format - although I always set both success and failure attributes, but I don't think that is necessary.
All the fields and the json return look right. I am assuming you are not doing the load until after the form is rendered. I don't know if having that reader attribute on the form would interfere with the ajax load. I would just step through it all in the firebug debugger, including the load success handler.
How much does getting a small tattoo on your hip/stomach hurt?
Do anyone else have an itchy anus? ?
|