-
1 Nov 2011 3:36 PM #1
Answered: Set default value on select form field
Answered: Set default value on select form field
Given this:
How do I start with a blank value - If I add a blank option is shows in drop down.Code:xtype: 'selectfield', name: 'gender', label: 'Gender', required: false, useClearIcon: true, options: [{ text: 'Male', value: 'male' }, { text: 'Female', value: 'female' }]
Thanks!
-
Best Answer Posted by cyberwombat
Evidently you have to trick it. It's a two step process. In the view setup a listener for the painted event:
And then in the select do NOT put options:Code:Ext.define('MyApp.view.Register', { extend: 'Ext.Panel', xtype: 'register', initialize: function() { this.on({ scope: this, painted: 'onPainted', }); }, onPainted: function() { Ext.getCmp('gender').setOptions([ //use id of select {text: 'Male', value: 'male'}, {text: 'Female', value: 'female'} ]) }, .....
Code:{ xtype: 'selectfield', name: 'gender', label: 'Gender', id: 'gender', //we need an id for the listener required: false, useClearIcon: true, placeHolder: '' //this can be anything },
-
2 Nov 2011 6:26 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 34,107
- Vote Rating
- 453
- Answers
- 3156
If you want text to be shown when there is no value, then placeHolder is the config you want to use. It's marked as deprecated but it will not be and that message will be removed on next release.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
2 Nov 2011 8:57 AM #3
Doesn't seem to work for selects.
This works:
But this doesn'tCode:{ xtype: 'textfield', label: 'Phone Number', required: true, placeHolder: '9992222', },
Code:{ xtype: 'selectfield', name: 'gender', label: 'Gender', required: false, useClearIcon: true, placeHolder: 'Female', //or any other value such as female, hello, blank options: [{ text: 'Male', value: 'male' }, { text: 'Female', value: 'female' }] },Last edited by cyberwombat; 2 Nov 2011 at 8:57 AM. Reason: mispell
-
2 Nov 2011 9:15 AM #4
Evidently you have to trick it. It's a two step process. In the view setup a listener for the painted event:
And then in the select do NOT put options:Code:Ext.define('MyApp.view.Register', { extend: 'Ext.Panel', xtype: 'register', initialize: function() { this.on({ scope: this, painted: 'onPainted', }); }, onPainted: function() { Ext.getCmp('gender').setOptions([ //use id of select {text: 'Male', value: 'male'}, {text: 'Female', value: 'female'} ]) }, .....
Code:{ xtype: 'selectfield', name: 'gender', label: 'Gender', id: 'gender', //we need an id for the listener required: false, useClearIcon: true, placeHolder: '' //this can be anything },


Reply With Quote