ExtJs 4: submit form on enter

It’s a shame that such a powerful framework as ExtJs 4 does not have this feature built-in.

function submitOnEnter(field, event) {
	if (event.getKey() == event.ENTER) {
		field.up('form').getForm().submit();
	}
}

var form = Ext.create('Ext.form.Panel', {
	...
	defaults: {
		...
		listeners: {
			specialkey: submitOnEnter
		}
	},
	submit: function() {
		// Your submit code
	}
});

The above code automatically adds the listener to every field in the form. Alternatively you may do it yourself:

items: [{
	fieldLabel: 'Email',
	name: 'email',
	vtype: 'email',
	maxLength: 64,			
	allowBlank: false,
	listeners: {
		specialkey: submitOnEnter
	}
}]

See it all in action.

This entry was posted in Programming and tagged , . Bookmark the permalink.

4 Responses to ExtJs 4: submit form on enter

  1. shaswath says:

    hello thanks for posting

  2. Francis says:

    It would be too powerful if it did.

  3. That’s why I hate ExtJS. HTML native forms does this automatically, while in ExtJS you should write code, and a pretty dirty code.

  4. MoneyOnlinez says:

    It works man, save my time! Now I didn’t need to put listeners in every field.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>