PDA

View Full Version : Load data in existing Form



pex
29 Jun 2007, 2:16 AM
Hello,

I have build a form using HTML and I wrapped it in an Ext.form.Form - I then want to be able to load data into the form object by using form.load(). I have the following code:

HTML of the form


<form target="_self" id="personForm" name="personForm" method="post" action="/handler.php">
<ol id="formFields">

<li class="">
<label class="desc">Personal Details</label>
</li>
<li>
<span class="t">
<input class="text h" name="title" type="text"> <label>Title</label>
</span>
<span class="f">
<input class="text h" name="fname" type="text"> <label>First name</label>
</span>
<span class="f">
<input class="text h" name="lname" type="text"> <label>Last name</label>
</span>
</li>
</ol>
</form>


Wrap the form in an Ext.form object


this.formObj = new Ext.form.Form('personForm', {
waitMsgTarget: 'box-bdd'
});


Then i load the data into the form like this:


this.formObj.load({url:this.url, params:parms, waitMsg:'Loading Data'});


I get a good reply from the load (object contains 'success' and 'data' fields) however it just does not populate the form fields. Any idea why not and how to fix this? Thanks in advance!

fay
29 Jun 2007, 2:33 AM
I'm not 100% sure but I think you will need to create field objects and apply them to the inputs, before calling load():


var eTitle = new Ext.form.TextField({/* Your Config */});
eTitle.applyTo('title');

You should also use the id tag in the HTML:


<input class="text" id="title" name="title" type="text">

As I say, I'm not positive this will work, but it's something to try...

pex
29 Jun 2007, 3:13 AM
yea, that did the trick, also you have to add the Form Fields to the form object, so:



var f = new Ext.form.TextField({});
f.applyTo(el);
formObj.add(f);


Where formObj is a var holding your Ext.form.BasicForm object