PDA

View Full Version : Dynamic Form



JoePie
26 Oct 2011, 2:31 AM
I am using a simple form that I found in the examples. What I want is for the form to be populated with dynamic data when the user opens the form. No buttons, like I saw in the XML demo. I don't know XML, so I am trying to use JSON store. If someone could please help me out. Here is the code I am using:


Ext.require([
'Ext.form.*',
'Ext.layout.container.Column',
'Ext.tab.Panel'
]);

Ext.onReady(function(){

Ext.define('formModel', {
extend:'Ext.data.Model',

fields: [
{name: 'first', type: 'string'},
{name: 'last', type: 'string'},
{name: 'company', type: 'string'}
]
});

Ext.QuickTips.init();

var bd = Ext.getBody();


/*
* ================ Simple form =======================
*/
bd.createChild({tag: 'h2', html: 'Form 1 - Very Simple'});

var memoryStore = Ext.create('Ext.data.Store',{
model: 'formModel',
proxy: {
type: 'ajax',
url: ('formData.html'),
reader: 'json'
},
autoLoad: true
});


var simple = Ext.create('Ext.form.Panel', {

url:'save-form.php',
frame:true,
title: 'Simple Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
store: memoryStore, //**Store added by me
fieldDefaults: {
msgTarget: 'side',
labelWidth: 75
},
defaultType: 'textfield',
defaults: {
anchor: '100%'
},

items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank:false
},{
fieldLabel: 'Last Name',
name: 'last'
},{
fieldLabel: 'Company',
name: 'company'
}],

buttons: [{
text: 'Save'
},{
text: 'Cancel'
}]
});

simple.render(document.body);
});




And the data,

[ {"first":"Baba","last":"Booey","company":"JP"} ]

Thank you for any help

JambaFun
26 Oct 2011, 6:22 AM
Hi JoePie,

My only advice is to read the official guides from Sencha.

http://docs.sencha.com/ext-js/4-0/#!/guide/getting_started
http://docs.sencha.com/ext-js/4-0/#!/guide/class_system
http://docs.sencha.com/ext-js/4-0/#!/guide/application_architecture

You are not going to learn anything by using copy-paste code. If these guides intimidate you or make no sense you probably have to start with something easier than Ext JS.

Best Regards

kelv1n
27 Oct 2011, 1:19 PM
Hi JoePie, sorry I can't help with, I'm a newb myself.. but I'd like to reply to JambaFuns comment - It depends, some people learn better following instruction, others learn by dissecting and rebuilding (copy-n-paste)..