ExtJS ComboBox Hidden Field Issues

No Comments

As you might already know, despite looking like a typical select box, Ext.form.ComboBox doesn’t behave exactly as you would expect since it submits the display text instead of the option value. The documentation states:

A ComboBox works in a similar manner to a traditional HTML <select> field. The difference is that to submit the valueField, you must specify a hiddenName to create a hidden input field to hold the value of the valueField. The displayField is shown in the text field which is named according to the name.

this.add([
	{
		xtype: 'combo',
		name: 'suffix',
		hiddenName: 'suffixId', // post this name
		hiddenValue: 0, // default value
		fieldLabel: 'Suffix',
		mode: 'local',
		store: this.suffixStore,
		valueField: 'key',
		displayField: 'display',
		triggerAction: 'all',
		forceSelection: true,
		allowBlank: true
	}
]);

Adding a hiddenName and a default value in hiddenValue does the trick, the default value (0) is set in the hidden field until a user chooses a different value. Unfortunately this breaks when the ComboBox is set to allow blanks and the user tabs over the field. When this happens, the hiddenValue is set to a null string and the user is never prompted to select a value.

Upon form submission, the hiddenField (suffixId) will be set to neither the default nor a valid value.

One solution is to listen for the focus and blur events to reset the value of the hidden field when it has been set to a null string.

this.add([
	{
		xtype: 'combo',
		name: 'suffix',
		hiddenName: 'suffixId',
		hiddenValue: 0,
		fieldLabel: 'Suffix',
		mode: 'local',
		store: this.suffixStore,
		valueField: 'key',
		displayField: 'display',
		triggerAction: 'all',
		forceSelection: true,
		allowBlank: true,
		listeners: {
			'focus': this.handleSuffixChange,
			'blur': this.handleSuffixChange,
			scope: this
		}
	}
]);

handleSuffixChange: function(field) {
	if (field.value=='') {
		field.hiddenField.value = '0';
	}
}

Upon form submission you will be guaranteed a valid value, which is especially beneficial if you’re using the form values to populate a server side bean object.

Ext-JS Tasks & Progressbars a Match Made in Heaven

No Comments

Chris Boersma posted this example of using TaskRunner and TaskManager to keep a user informed while a task is handled server-side.

Tutorial: Ext-JS Charting and Mapping with Google Visualizations

6 Comments

Aaron Conran posted an entry about Ext.ux.GVisualizationPanel, a user extension that takes advantage of the similarities between the Ext data store and Google’s data table to allow reuse of an Ext data store with Google’s Visualization API.

Proceed to the tutorial.

Tutorial: Flickr Photo Gallery

2 Comments

This demo shows you how to retrieve today’s top rated photos from Flickr as the most recent uploads using jQuery and phpFlickr.

Creating an Apple Style Menu with Animation

No Comments

Kriesi Budschedl has posted a very detailed tutorial to help you build your own Apple.com style menu and adds a nice touch by animating it.

To construct the basic menu, Kriesi takes advantage of CSS Sprites, a technique to reduce the number of image files necessary to accomplish things like rollovers, without the need to preload the images using JavaScript.

A single image contains all the navigation menu options in their normal and active states and CSS rules are used to move the appropriate menu option into view. Once the basic menu is working, animation is added by using Kwicks for jQuery, a plugin written by Jerry Martin, resulting in the final product seen here.