Threaded View

  1. #1
    Sencha User cyberwombat's Avatar
    Join Date
    Oct 2011
    Posts
    237
    Vote Rating
    2
    Answers
    6
    cyberwombat is on a distinguished road

      0  

    Default Answered: Set default value on select form field

    Answered: Set default value on select form field


    Given this:
    Code:
    xtype: 'selectfield',
    			                    	name: 'gender',
                        				label: 'Gender',
                        				required: false,
                        				useClearIcon: true,
                        				options: [{
                        					text: 'Male',
                        					value: 'male'
                        				}, {
                        					text: 'Female',
                        					value: 'female'
                        				}]
    How do I start with a blank value - If I add a blank option is shows in drop down.
    Thanks!

  2. Evidently you have to trick it. It's a two step process. In the view setup a listener for the painted event:

    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'}
            ])
        },
      .....
    And then in the select do NOT put options:
    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
    },

Thread Participants: 1