In actual web development, most of the time it takes to process form. There are also many controls in this aspect in the ext framework, and there is also a special formpanel layout. By default, all the controls placed on the panel are placed with line breaks, in practical applications, horizontal layout is required for the sake of appearance, especially the radio controls. At this time, we need to re-customize the layout of these controls. In this example, CSS is used to implement these functions,Paste one.
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> horizontal layout test (CSS) of the formpanel panel and Form Control in ext </title>
<LINK rel = "stylesheet" type = "text/CSS" Media = "all" href = "../EXT/resources/CSS/ext-all.css"/>
<Style type = "text/CSS" Media = "all">
. Allow-float {clear: none! Important;}/* allow this element to float */
. Stop-float {clear: both! Important;}/* prevents this element from floating */
. Sex-male {float: Left ;}
. Sex-female {float: Left; padding: 0 0 0 20px ;}
. Age-field {float: Left; padding: 0 0 58px; * padding: 0 0 0 50px! Important; * padding: 0 0 0 50px ;}
</Style>
</Head>
<Body>
<SCRIPT type = "text/JavaScript" src = "../EXT/adapter/EXT/ext-base.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "../EXT/ext-all.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "../EXT/build/locale/ext-lang-zh_CN.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript"> Ext. blank_image_url = '../EXT/resources/images/default/s.gif'; </SCRIPT>
<SCRIPT type = "text/JavaScript">
Ext. onready (function (){
// Create a form panel
VaR fp = new Ext. Form. formpanel ({
Buttonalign: 'center ',
Labelalign: 'right ',
Labelwidth: 40,
Frame: True,
Bodystyle: 'padding: 8px 0 0 0 ;',
Items :[{
Xtype: 'textfield ',
Fieldlabel: 'name ',
Name: 'n' _ Username ',
ID: 'I _ username ',
Width: 320
},{
Xtype: 'Radio ',
Fieldlabel: 'gender ',
Boxlabel: 'male ',
Name: 'sex ',
ID: 'male ',
Itemcls: 'sex-Male', // float to the left to handle horizontal control la s
Clearcls: 'Allow-float', // The two sides are allowed to float. The actually generated HTML structure contains a special Div to block the float.
Checked: True
},{
Xtype: 'Radio ',
Boxlabel: 'femal ',
Name: 'sex ',
ID: 'female ',
Itemcls: 'sex-female ', // float to the left to process the horizontal control
Clearcls: 'Allow-float', // allow floating on both sides
Hidelabel: True // The preceding "gender" label is not displayed.
},{
Xtype: 'textfield ',
Fieldlabel: 'age ',
Name: 'n' _ age ',
ID: 'I _ age ',
Itemcls: 'Age-field ', // float to the left to handle horizontal control la s
Width: 133
},{
Xtype: 'textfield ',
Fieldlabel: 'address ',
Name: 'n' _ address ',
ID: 'I _ address ',
Itemcls: 'Stop-float ', // float is not allowed.
Width: 320
}],
Buttons :[{
Text: 'OK ',
Handler: onok // the actual application is generally to process the FP. getform. Submit () event.
},{
Text: 'reset ',
Handler: function () {FP. getform (). Reset ();}
}],
Keys: [{// handle keyboard carriage return events
Key: Ext. eventobject. Enter,
FN: onok,
Scope: This
}]
});
// Confirm the button event. Here, we just get the values of each control. The actual application is generally combined with the background script.
Function onok (){
VaR strmsg;
Strmsg = 'name: '+ FP. getcomponent (' I _ username'). getvalue () + ', Gender :';
If (FP. getcomponent ('male'). Checked) strmsg + = 'male ';
If (FP. getcomponent ('female'). Checked) strmsg + = 'femal ';
Strmsg + = ', age:' + FP. getcomponent ('I _ age'). getvalue ();
Strmsg + = ', address:' + FP. getcomponent ('I _ address'). getvalue ();
Alert (strmsg );
}
// Create the Main Window
New Ext. Window ({
Title: 'ext formpanel panel and Form Control horizontal layout test (CSS )',
Width: 400,
Closable: false,
Collapsible: True,
Draggable: false,
Resizable: false,
Modal: True,
Border: false,
Items: [FP],
Buttons: []
}). Show ();
});
</SCRIPT>
</Body>
</Html>