Ext Forms Using cfExt
Thursday January 31, 2008 4:26 PM
Word Count: 956
<ext:application path=".">
<ext:form id="simpleform" title="Simple Form" display="form1" width="400" collapsible="true" fieldWidth="250">
<ext:input type="hidden" name="id" value="1"/>
<ext:input type="text" name="first" label="First Name" required="false"/>
<ext:input type="text" name="last" label="Last Name" required="false"/>
<ext:input type="text" name="company" label="Company" />
<ext:input type="text" name="email" label="Email"/>
<ext:input type="time" name="time" label="Time" min="8:00am" max="5:00pm"/>
<ext:input type="date" name="date" label="Date"/>
<ext:textarea name="ta" label="Notes"/>
<ext:button text="Cancel"/>
<ext:button type="submit" text="Save" onClick="simpleForm.form.submit()"/>
</ext:form>
</ext:application>
<div id="form1" style="margin:20px;">
</div>
<ext:form id="simpleform" title="Simple Form" display="form1" width="400" collapsible="true" fieldWidth="250">
<ext:input type="hidden" name="id" value="1"/>
<ext:input type="text" name="first" label="First Name" required="false"/>
<ext:input type="text" name="last" label="Last Name" required="false"/>
<ext:input type="text" name="company" label="Company" />
<ext:input type="text" name="email" label="Email"/>
<ext:input type="time" name="time" label="Time" min="8:00am" max="5:00pm"/>
<ext:input type="date" name="date" label="Date"/>
<ext:textarea name="ta" label="Notes"/>
<ext:button text="Cancel"/>
<ext:button type="submit" text="Save" onClick="simpleForm.form.submit()"/>
</ext:form>
</ext:application>
<div id="form1" style="margin:20px;">
</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.<ext:combobox name="favnumber" label="Favorite Number" emptyText="[ Select Your Favorite Number]">
<cfloop from="1" to="100" index="i">
<ext:option value="#i#"><cfoutput>#i#</cfoutput></ext:option>
</cfloop>
</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.
<cfloop from="1" to="100" index="i">
<ext:option value="#i#"><cfoutput>#i#</cfoutput></ext:option>
</cfloop>
</ext:combobox>
<ext:application path=".">
<ext:form title="Simple Form with Fieldsets" display="form2" width="400" collapsible="true">
<ext:fieldset title="User Information" checkboxToggle="true" fieldWidth="225">
<ext:input type="text" name="first" label="First Name" allowBlank="false"/>
<ext:input type="text" name="last" label="Last Name" allowBlank="false"/>
<ext:input type="text" name="company" label="Company"/>
<ext:input type="text" name="email" label="Email"/>
</ext:fieldset>
<ext:fieldset title="Phone Numbers" collapsible="true" fieldWidth="225">
<ext:input type="text" name="home" label="Home"/>
<ext:input type="text" name="business" label="Business"/>
<ext:input type="text" name="mobile" label="Mobile"/>
<ext:input type="text" name="fax" label="Fax"/>
</ext:fieldset>
<ext:button text="Cancel"/>
<ext:button text="Save"/>
</ext:form>
</ext:application>
<ext:form title="Simple Form with Fieldsets" display="form2" width="400" collapsible="true">
<ext:fieldset title="User Information" checkboxToggle="true" fieldWidth="225">
<ext:input type="text" name="first" label="First Name" allowBlank="false"/>
<ext:input type="text" name="last" label="Last Name" allowBlank="false"/>
<ext:input type="text" name="company" label="Company"/>
<ext:input type="text" name="email" label="Email"/>
</ext:fieldset>
<ext:fieldset title="Phone Numbers" collapsible="true" fieldWidth="225">
<ext:input type="text" name="home" label="Home"/>
<ext:input type="text" name="business" label="Business"/>
<ext:input type="text" name="mobile" label="Mobile"/>
<ext:input type="text" name="fax" label="Fax"/>
</ext:fieldset>
<ext:button text="Cancel"/>
<ext:button text="Save"/>
</ext:form>
</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.
<ext:form title="Mult Column, Nested Layouts and Anchoring" display="form3" width="600" collapsible="true" labelAlign="top">
<ext:columns>
<ext:column width=".5">
<ext:input type="text" name="first" label="First Name" anchor="95%"/>
<ext:input type="text" name="last" label="Last Name" anchor="95%"/>
</ext:column>
<ext:column width=".5">
<ext:input type="text" name="company" label="Company" anchor="95%"/>
<ext:input type="text" name="email" label="Email" anchor="95%"/>
</ext:column>
</ext:columns>
<ext:htmlEditor label="Biography" height="400"/>
<ext:button text="Cancel"/>
<ext:button text="Save"/>
</ext:form>
<ext:columns>
<ext:column width=".5">
<ext:input type="text" name="first" label="First Name" anchor="95%"/>
<ext:input type="text" name="last" label="Last Name" anchor="95%"/>
</ext:column>
<ext:column width=".5">
<ext:input type="text" name="company" label="Company" anchor="95%"/>
<ext:input type="text" name="email" label="Email" anchor="95%"/>
</ext:column>
</ext:columns>
<ext:htmlEditor label="Biography" height="400"/>
<ext:button text="Cancel"/>
<ext:button text="Save"/>
</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.
<ext:form title="Inner Tabs" display="form4" width="600" collapsible="true" labelAlign="top">
<ext:columns>
<ext:column width=".5">
<ext:input type="text" name="first" label="First Name" anchor="95%"/>
<ext:input type="text" name="last" label="Last Name" anchor="95%"/>
</ext:column>
<ext:column width=".5">
<ext:input type="text" name="company" label="Company" anchor="95%"/>
<ext:input type="text" name="email" label="Email" anchor="95%"/>
</ext:column>
</ext:columns>
<ext:tabPanel height="250">
<ext:tab title="Personal Details" width="230" layout="form">
<ext:input name="firstName" label="First Name"/>
<ext:input name="lastName" label="Last Name"/>
<ext:input name="company" label="Company"/>
<ext:input name="email" label="Email Address"/>
</ext:tab>
<ext:tab title="Phone Numbers" width="230" layout="form">
<ext:input name="home" label="Home"/>
<ext:input name="business" label="Business"/>
<ext:input name="mobile" label="Mobile"/>
<ext:input name="fax" label="Fax"/>
</ext:tab>
<ext:tab title="Biography" layout="fit">
<ext:htmlEditor label="Biography" height="200"/>
</ext:tab>
</ext:tabPanel>
<ext:button text="Cancel"/>
<ext:button text="Save"/>
</ext:form>
<ext:columns>
<ext:column width=".5">
<ext:input type="text" name="first" label="First Name" anchor="95%"/>
<ext:input type="text" name="last" label="Last Name" anchor="95%"/>
</ext:column>
<ext:column width=".5">
<ext:input type="text" name="company" label="Company" anchor="95%"/>
<ext:input type="text" name="email" label="Email" anchor="95%"/>
</ext:column>
</ext:columns>
<ext:tabPanel height="250">
<ext:tab title="Personal Details" width="230" layout="form">
<ext:input name="firstName" label="First Name"/>
<ext:input name="lastName" label="Last Name"/>
<ext:input name="company" label="Company"/>
<ext:input name="email" label="Email Address"/>
</ext:tab>
<ext:tab title="Phone Numbers" width="230" layout="form">
<ext:input name="home" label="Home"/>
<ext:input name="business" label="Business"/>
<ext:input name="mobile" label="Mobile"/>
<ext:input name="fax" label="Fax"/>
</ext:tab>
<ext:tab title="Biography" layout="fit">
<ext:htmlEditor label="Biography" height="200"/>
</ext:tab>
</ext:tabPanel>
<ext:button text="Cancel"/>
<ext:button text="Save"/>
</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 RIAForgeDynamic Forms Example
