Hybrid View

  1. #1
    Sencha User cyberwombat's Avatar
    Join Date
    Oct 2011
    Posts
    237
    Answers
    6
    Vote Rating
    2
    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
    },

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,408
    Answers
    3549
    Vote Rating
    851
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

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

      0  

    Default


    Doesn't seem to work for selects.

    This works:
    Code:
    {
        xtype: 'textfield',
        label: 'Phone Number',
        required: true,
        placeHolder: '9992222',
    },
    But this doesn't
    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

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

      0  

    Default


    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