I have been adding away whenever I get a chance and this library is starting to grow. Today I want to walk through on how I have implemented forms as well get your thoughts on a couple of things. If you skip to the bottom there is a link to the live example of what I am talking about in this article. If you have been reading my examples up until now then you know the base of our application is the ext:application tag. This is an example of a very basic form. As you can the syntax is very clean and the end result is pretty nice. Once you have a form there are some pretty cool things you can do with it and I'll save that for a rainy day. You will notice we make use of hidden, text, date, time and textarea form fields. I pushed many items into a tag called input to try and make it similar to HTML.
view plain print about
1<ext:application path=".">
2
3    <ext:form id="simpleform" title="Simple Form" display="form1" width="400" collapsible="true" fieldWidth="250">
4            
5        <ext:input type="hidden" name="id" value="1"/>
6        <ext:input type="text" name="first" label="First Name" required="false"/>
7        <ext:input type="text" name="last" label="Last Name" required="false"/>
8        <ext:input type="text" name="company" label="Company" />
9        <ext:input type="text" name="email" label="Email"/>
10        <ext:input type="time" name="time" label="Time" min="8:00am" max="5:00pm"/>
11        <ext:input type="date" name="date" label="Date"/>
12        <ext:textarea name="ta" label="Notes"/>
13        
14        <ext:button text="Cancel"/>
15        <ext:button type="submit" text="Save" onClick="simpleForm.form.submit()"/>
16        
17    </ext:form>
18</ext:application>
19
20<div id="form1" style="margin:20px;">
21</div>
How about a combo box? In Ext you can load the combo box using JSON but for now I have implemented the static route and the data version should be coming soon. Here is how to add a combo box, pretty easy huh.
view plain print about
1<ext:combobox name="favnumber" label="Favorite Number" emptyText="[ Select Your Favorite Number]">
2    <cfloop from="1" to="100" index="i">
3    <ext:option value="#i#"><cfoutput>#i#</cfoutput></ext:option>
4    </cfloop>
5</ext:combobox>
This next example is really cool. First off you will notice the use of field sets. The cool part about field sets in Ext is that you can collapse them using a collapse tool or by toggle the the field set with a checkbox.
view plain print about
1<ext:application path=".">
2<ext:form title="Simple Form with Fieldsets" display="form2" width="400" collapsible="true">
3    
4    <ext:fieldset title="User Information" checkboxToggle="true" fieldWidth="225">
5        <ext:input type="text" name="first" label="First Name" allowBlank="false"/>
6        <ext:input type="text" name="last" label="Last Name" allowBlank="false"/>
7        <ext:input type="text" name="company" label="Company"/>
8        <ext:input type="text" name="email" label="Email"/>
9    </ext:fieldset>
10    
11    <ext:fieldset title="Phone Numbers" collapsible="true" fieldWidth="225">
12        <ext:input type="text" name="home" label="Home"/>
13        <ext:input type="text" name="business" label="Business"/>
14        <ext:input type="text" name="mobile" label="Mobile"/>
15        <ext:input type="text" name="fax" label="Fax"/>
16    </ext:fieldset>            
17    
18    <ext:button text="Cancel"/>
19    <ext:button text="Save"/>
20    
21</ext:form>
22</ext:application>
The next example shows how you can lay your fields out using a column style layout. This example also shows you the Ext HTML Editor. Again, the code could not get any easier.
view plain print about
1<ext:form title="Mult Column, Nested Layouts and Anchoring" display="form3" width="600" collapsible="true" labelAlign="top">
2    
3    <ext:columns>
4        <ext:column width=".5">
5            <ext:input type="text" name="first" label="First Name" anchor="95%"/>
6            <ext:input type="text" name="last" label="Last Name" anchor="95%"/>
7        </ext:column>
8        <ext:column width=".5">
9            <ext:input type="text" name="company" label="Company" anchor="95%"/>
10            <ext:input type="text" name="email" label="Email" anchor="95%"/>
11        </ext:column>
12    </ext:columns>    
13    
14    <ext:htmlEditor label="Biography" height="400"/>
15    
16    <ext:button text="Cancel"/>
17    <ext:button text="Save"/>
18                
19</ext:form>
Finally this example shows how layouts can be combined with forms to create easy to use interfaces. This form has a section at the bottom that contains tabs.
view plain print about
1<ext:form title="Inner Tabs" display="form4" width="600" collapsible="true" labelAlign="top">
2    
3    <ext:columns>
4        <ext:column width=".5">
5            <ext:input type="text" name="first" label="First Name" anchor="95%"/>
6            <ext:input type="text" name="last" label="Last Name" anchor="95%"/>
7        </ext:column>
8        <ext:column width=".5">
9            <ext:input type="text" name="company" label="Company" anchor="95%"/>
10            <ext:input type="text" name="email" label="Email" anchor="95%"/>
11        </ext:column>
12    </ext:columns>    
13    
14    <ext:tabPanel height="250">
15        <ext:tab title="Personal Details" width="230" layout="form">
16            <ext:input name="firstName" label="First Name"/>
17            <ext:input name="lastName" label="Last Name"/>
18            <ext:input name="company" label="Company"/>
19            <ext:input name="email" label="Email Address"/>
20        </ext:tab>
21        <ext:tab title="Phone Numbers" width="230" layout="form">
22            <ext:input name="home" label="Home"/>
23            <ext:input name="business" label="Business"/>
24            <ext:input name="mobile" label="Mobile"/>
25            <ext:input name="fax" label="Fax"/>
26        </ext:tab>
27        <ext:tab title="Biography" layout="fit">
28            <ext:htmlEditor label="Biography" height="200"/>
29        </ext:tab>
30    </ext:tabPanel>
31
32    
33    <ext:button text="Cancel"/>
34    <ext:button text="Save"/>
35                
36</ext:form>
I think I have a great foundation of code to build on now. The really great thing is the way the core has been implemented. This will allow for everything to fit together just nice. When I got to the forms section I took a look at examples and he had some right ideas there so I ran with them. The final thing with the forms is going to get the submit handler working. I know how to submit the forms its just a matter of how it should be implemented for those who know nothing about Ext. Anyone with ideas of how it should work I would love to hear them. Based on that Ill figure out how to write the back end code. If you have a chance download the code using the link below and give me your feedback. Also there is a link to a live demo of the forms talked about in this article. cfExt Project Page on RIAForge
Dynamic Forms Example