In extjs4 how to set focus of textfield - extjs4

I am working in extjs4. i have activation view form as-
For entering key i have taken item as-
{
margin:'5 5 5 5',
xtype: 'fieldcontainer',
fieldLabel: 'Enter key',
layout: 'hbox',
combineErrors: true,
defaults: {
hideLabel: true
},
items: [{xtype: 'textfield', fieldLabel: 'a', name: 'a', width: 80, allowBlank:false, margins: '0 5 0 0'},
{xtype: 'textfield', fieldLabel: 'b', name: 'b', width: 80, allowBlank: false, margins: '0 5 0 0'},
{xtype: 'textfield', fieldLabel: 'c', name: 'c', width: 80, allowBlank: false, margins: '0 5 0 0'},
{xtype: 'textfield', fieldLabel: 'd', name: 'd', width: 80, allowBlank: false, margins: '0 5 0 0'},
{xtype: 'textfield', fieldLabel: 'e', name: 'e', width: 80, allowBlank: false, margins: '0 5 0 0'}]},
I want to restrict number of characters in each block to 5. And after entering 5 char in first block,i want to set focus to next block automatically. So how to implement this in extjs4

You can add key listeners. You will have configure your textfield something like this:
{
xtype: 'textfield',
//...other props...
name: 'a',
maxLength: 5,
enableKeyEvents: true,
enforceMaxLength: true,
listeners: {
keyup: function(f, e) {
if (f.getValue().length == 5)
{
var nextField = f.next();
if (nextField && Ext.isFunction(nextField.focus)) {
nextField.focus();
}
}
}
}
}
You could even enableKeyEvents, maxLength, enforceMaxLength, and the listeners to your defaults, if they are the same for all the fields.

Related

ExtJS Multipart textfield in a single row

How can I create this type of From using ExtJS 4.
Yes I did Solved it using Ext.form.FieldSet.
Ext.create('Ext.form.FieldSet', {
title: 'Deposit A/C No',
defaults: {
labelWidth: 89,
layout: {
type: 'hbox',
defaultMargins: {top: 0, right: 5, bottom: 0, left: 0}
}
},
items: [
{
xtype: 'fieldcontainer',
combineErrors: true,
msgTarget: 'side',
defaults: {
hideLabel: true
},
items: [
{
xtype: 'textfield',
width: 15,
name: 'part1',
value: '2',
maskRe: /[0-9.]/,
readOnly: true
},
{xtype: 'displayfield', value: '-'},
{
xtype: 'textfield',
width: 30,
name: 'part2',
value: '050',
maskRe: /[0-9.]/,
readOnly: true
},
{xtype: 'displayfield', value: '-'},
{
xtype: 'textfield',
width: 30,
name: 'part3',
value: '213',
maskRe: /[0-9.]/,
maxLength: 3,
enforceMaxLength: 3,
keyup: function () {
var part4 = this.getValue();
if (part4.length >= 3) {
var form = this.up('form').getForm();
form.findField("part4").focus();
}
}
},
{xtype: 'displayfield', value: '-'}, {
xtype: 'textfield',
width: 30,
name: 'part4',
maskRe: /[0-9.]/,
enableKeyEvents: true,
maxLength: 2,
enforceMaxLength: 2,
listeners: {
afterrender: function (field) {
field.focus();
},
keyup: function () {
var part4 = this.getValue();
if (part4.length >= 2) {
var form = this.up('form').getForm();
form.findField("part5").focus();
}
}
}
},
{xtype: 'displayfield', value: '-'},
{
xtype: 'textfield',
width: 70,
name: 'part5',
maskRe: /[0-9.]/,
//msgTarget: 'down',
maxLength: 6,
enforceMaxLength: 6,
msgTarget: 'side',
enableKeyEvents: true,
listeners: {
//keyup: setCheckValue,
//specialkey: submitOnEnter
}
},
{xtype: 'displayfield', value: '-'}, {
xtype: 'textfield',
width: 30,
name: 'part6',
maskRe: /[0-9.]/,
readOnly: true
}
]
}
]
});

sencha touch RadioGroup not working

Does RadioGroup works properly in sencha touch ?
Example :
var myRadioGroup = new Ext.form.RadioGroup({
id: 'myGroup',
xtype: 'radiogroup',
fieldLabel: 'Single Column',
// Arrange radio buttons into three columns, distributed vertically
columns: 3,
vertical: true,
items: [
{boxLabel: 'Item 1', name: 'rb', inputValue: '1'},
{boxLabel: 'Item 2', name: 'rb', inputValue: '2', checked: true},
{boxLabel: 'Item 3', name: 'rb', inputValue: '3'},
{boxLabel: 'Item 4', name: 'rb', inputValue: '4'},
{boxLabel: 'Item 5', name: 'rb', inputValue: '5'},
{boxLabel: 'Item 6', name: 'rb', inputValue: '6'}
]
});
var resultsPanel = Ext.create('Ext.Panel', {
title: 'Results',
style:"margin:50px 0 0 10px;",
layout: {
type: 'vbox', // Arrange child items vertically
align: 'stretch',//, // Each takes up full width
padding: 55
},
defaults: {
labelWidth: '85%',
labelWrap: true,
labelAlign: 'right'
},
items:[{
xtype: 'radiogroup',
fieldLabel: 'RadioGroup',
items:myRadioGroup
}]
});
Ext.viewport.add(resultsPanel);
This generates the following error :
[ERR] C2008: Requirement had no matching files (Ext.form.RadioGroup) -- C:\xampp\htdocs\testRadio\app.js:17:30.
Does anyone have an idea ,i tried updating app.json (not working ) ,also i searched for RadioGroup.js in touch/src/form/ but did not find it .
Sencha don't have radio group field , It has radio field only.
refer this. http://docs-origin.sencha.com/touch/2.4/2.4.1-apidocs/#!/api/Ext.field.Radio
for implementing Radio group give same name to all radio field:
ex:
var form = Ext.create('Ext.form.Panel', {
fullscreen: true,
items: [
{
xtype: 'radiofield',
name : 'color',
value: 'red',
label: 'Red',
checked: true
},
{
xtype: 'radiofield',
name : 'color',
value: 'green',
label: 'Green'
},
{
xtype: 'radiofield',
name : 'color',
value: 'blue',
label: 'Blue'
}
]
});

Extjs checkboxfield not rendering in Apache Tomcat

We are using tomcat 6.0.36 and trying to do simple check box example but check boxes are not rendered rest everything working fine
All the text rendered properly, i have created some pages with tabs, forms and grids all pages rendering except checkboxes in them.
Ext.onReady(function() {
Ext.QuickTips.init();
var fsf = Ext.create('Ext.form.Panel', {
url:'save-form.php',
frame:true,
title: 'Simple Form with FieldSets',
bodyStyle:'padding:5px 5px 0',
width: 350,
fieldDefaults: {
msgTarget: 'side',
labelWidth: 75
},
defaults: {
anchor: '100%'
},
items: [{
xtype:'fieldset',
checkboxToggle:true,
title: 'User Information',
defaultType: 'textfield',
collapsed: true,
layout: 'anchor',
defaults: {
anchor: '100%'
},
items :[{
fieldLabel: 'First Name',
name: 'first',
allowBlank:false
},{
fieldLabel: 'Last Name',
name: 'last'
},{
fieldLabel: 'Company',
name: 'company'
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}]
},{
xtype:'fieldset',
title: 'Phone Number',
collapsible: true,
defaultType: 'textfield',
layout: 'anchor',
defaults: {
anchor: '100%'
},
items :[{
fieldLabel: 'Home',
name: 'home',
value: '(888) 555-1212'
},{
fieldLabel: 'Business',
name: 'business'
},{
fieldLabel: 'Mobile',
name: 'mobile'
},{
fieldLabel: 'Fax',
name: 'fax'
}]
}],
buttons: [{
text: 'Save'
},{
text: 'Cancel'
}],
renderTo: 'build-dynaForm'
})
});
Thanks in advance
Raj
On your form no checkboxes. If you add them, they will be displayed:
{
fieldLabel: 'Checkbox',
xtype: 'checkbox',
name: 'name1'
},{
fieldLabel: 'Checkbox',
xtype: 'checkbox',
name: 'name2'
},{
fieldLabel: 'Checkbox',
xtype: 'checkbox',
name: 'name3'
}
See http://jsfiddle.net/3FBzM/

How can I increase the spacing between items in a VBOX using ExtJS 4.1?

So I'm using ExtJS 4.1. I have a viewport that contains two items. They are stacked correctly but I want to put some space between them. Margins don't seem to work.
var required = '<span style="color:red;font-weight:bold" data-qtip="Required">*</span>';
Ext.onReady(function() {
Ext.QuickTips.init();
window.formPanel = Ext.widget({
bodyPadding: '5 5 0',
collapsible: false,
defaultType: 'textfield',
frame: true,
id: 'formPanel',
layout: 'form',
renderTo: '',
title: 'Spring Demo 3 (Lookup Transfer Request)',
url: contextPath + '/users/ajax',
width: 450,
xtype: 'form',
buttons: [{
text: 'Check Status',
scope: this,
handler: function() {
formPanel.getForm().submit({
success: function(res, req) {
}
});
}
}],
fieldDefaults: {
msgTarget: 'side',
labelWidth: 105
},
items: [{
afterLabelTextTpl: required,
allowBlank: false,
fieldLabel: 'Username',
name: 'username',
value: ''
}, {
afterLabelTextTpl: required,
allowBlank: false,
fieldLabel: 'TXID',
name: 'txid',
value: ''
}]
});
window.resultsPanel = Ext.widget({
items: [{
id: 'labMessage',
margin: '0 0 0 10',
text: 'Waiting....',
xtype: 'label'
}],
title: 'Results',
xtype: 'panel'
});
window.viewPort = Ext.widget({
items: [formPanel, resultsPanel],
layout: {
align: 'center',
pack: 'center',
type: 'vbox'
},
margins: '10 10 10 10',
padding: '10 10 10 10',
renderTo: 'container',
xtype: 'viewport'
});
});
The Ext.layout.container.VBox layout has the padding and defaultMargins configs that will apply the respective styles to child components. I have no idea why the naming is inconsistent, but that's what the docs say.
Looking at your sample code, it looks like you're applying your margins to the wrong components. If you want spacing between your panels, put the margin/padding settings on the panels themselves instead of on their container.
window.resultsPanel = Ext.widget({
xtype: "panel",
title: "Results",
margin: "10 0 0 0", // Same as CSS ordering (top, right, bottom, left)
items: [{
xtype: "label",
id: "labMessage",
margin: "0 0 0 10",
text: "Waiting..."
}]
});

How to Increase Column Space in EXtJS Column Layout

i have designed an entry form as shown,
i need to have same space between test box and Middle name label.
My code is as follows,
var patientForm = new Ext.FormPanel({
layout: 'column',
columnWidth:1.5,
renderTo: "patientCreation",
frame: true,
autoScroll:true,
title: 'Create Patient',
bodyStyle: 'padding:9px',
width: 900,
items: [
{ xtype: 'textfield',
fieldLabel: 'FirstName',
name: 'firstName',
vtype : 'alpha',
allowBlank:false
},{
xtype: 'textfield',
fieldLabel: 'MiddleName',
name: 'middleName',
vtype : 'alpha'
},{
xtype: 'textfield',
fieldLabel: 'LastName',
name: 'lastName',
vtype : 'alpha',
allowBlank:false
},{
xtype: 'textfield',
fieldLabel: 'Email',
name: 'email',
vtype: 'email',
allowBlank:false
},
....
....
]
How to leave/increase space between text box and Middle name column?
If you know your number of columns, use column layout. Otherwise do this:
defaults: {
labelStyle: 'padding-left:10px;'
},
items: [...]
Add a defaults config to the container of the columns. All it's children will have the settings you define in defaults (docs). In this example there's just the margin setting (docs) in defaults that will be applied to each item/column.
Ext.create('Ext.panel.Panel', {
title: 'Column Layout - with default margins',
width: 350,
height: 250,
layout:'column',
defaults: {
margin: '0 15 0 0' //top right bottom left (clockwise) margins of each item/column
},
items: [{
title: 'Column 1',
columnWidth: 0.25
},{
title: 'Column 2',
columnWidth: 0.55
},{
title: 'Column 3',
columnWidth: 0.20
}],
renderTo: Ext.getBody()
});
The accepted solution works only with fields as columns. My solution works with any type of column.
PS: the column layout documentation is here.