1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    28
    Answers
    2
    Vote Rating
    1
    Dafram is on a distinguished road

      0  

    Default Answered: 4.1.1 - setValue on Combobox (with valueField) works only if forceSelection is false

    Answered: 4.1.1 - setValue on Combobox (with valueField) works only if forceSelection is false


    Hi all!

    I have a problem with ExtJs 4.1.1 and a Combobox with "displayField" param different from "valueField" param and with forceSelection:true.

    Here is my code:

    Code:
            Ext.define('modelCaratteristica', {
                extend: 'Ext.data.Model',
                fields: [
                    {name: 'idcara', type: 'int'},
                    {name: 'cadesc', type: 'string'}
                ]
            });
    
            var storeCaratteristica = Ext.create('Ext.data.Store', {
                model: 'modelCaratteristica',
                proxy: {
                    type: 'ajax',
                    url : 'storeCaratteristica.php',
                    reader: {
                        type: 'json'
                    }
                },
                autoLoad: true
            });
    
            var cbCaratteristica1 = Ext.create('Ext.form.field.ComboBox', {
                name: 'cbCaratteristica1',
                id: 'id_cbCaratteristica1',
                fieldLabel: 'Se Caratteristica',
                displayField: 'cadesc',
                valueField: 'idcara',
                width: 750,
                labelWidth: 100,
                store: storeCaratteristica,
                queryMode: 'local',
                allowBlank: false,
                forceSelection: true
            });
    My JSON store returns a JSON array like this:

    Code:
    [{"idcara":"1","cadesc":"AAAA"},{"idcara":"2","cadesc":"BBBB"},{"idcara":"3","cadesc":"CCCC"}]
    Now, I have displayField and valueField separated because I need to display description and to save to database the id.

    Now, if I make...

    Code:
    cbCaratteristica1.setValue(rec.idcara1); // where rec.idcara1 is numeric (for example "3")
    ... it only works (set combobox value to "CCCC") if my combobox has forceSelection: false.

    But I need forceSelection: true to avoid users to insert bad values. :-(

    PS: I have the same problem with ExtJs 4.0.7

  2. This is a timing issue. In the forceSelection, you are required to find a value in the store. In the other instance you are not.

    You making an ajax call. It is most likely the incoming results are causing havoc.
    Code:
    type: 'ajax',
    url : 'storeCaratteristica.php',
    reader: {
    	type: 'json'
    }
    You can either load the table before hand, or make the update upon success of the ajax call.

    Scott.

  3. #2
    Sencha User
    Join Date
    Mar 2010
    Posts
    245
    Answers
    2
    Vote Rating
    1
    Ex_Soft is an unknown quantity at this point

      0  

    Default


    Try to use Ext.form.field.ComboBox.reset() before Ext.form.field.ComboBox.setValue()

  4. #3
    Sencha User
    Join Date
    Feb 2012
    Posts
    28
    Answers
    2
    Vote Rating
    1
    Dafram is on a distinguished road

      0  

    Default


    Quote Originally Posted by Ex_Soft View Post
    Try to use Ext.form.field.ComboBox.reset() before Ext.form.field.ComboBox.setValue()
    Unfortunately it doesn't work :-(

  5. #4
    Sencha User
    Join Date
    Mar 2010
    Posts
    245
    Answers
    2
    Vote Rating
    1
    Ex_Soft is an unknown quantity at this point

      1  

    Default


    Quote Originally Posted by Dafram View Post
    Unfortunately it doesn't work
    This works fine.

  6. #5
    Sencha User
    Join Date
    Feb 2012
    Posts
    28
    Answers
    2
    Vote Rating
    1
    Dafram is on a distinguished road

      0  

    Default


    Quote Originally Posted by Ex_Soft View Post
    This works fine.
    Uhm... I see.

    Here I have my example: http://www.electricblueskies.com/smeraldo/es01.html

    It shows the difference between forceSelection = true and forceSelection = false

    PS: perhaps a delay problem? If I put an alert before the setValue instruction, sometimes, it works...

  7. #6
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,620
    Answers
    612
    Vote Rating
    397
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    I do not see reset() in your code as mention by Ex_Soft.

    Scott.

  8. #7
    Sencha User
    Join Date
    Feb 2012
    Posts
    28
    Answers
    2
    Vote Rating
    1
    Dafram is on a distinguished road

      0  

    Default


    Quote Originally Posted by scottmartin View Post
    I do not see reset() in your code as mention by Ex_Soft.

    Scott.
    Updated my code with reset(), but the same thing...

    I think it is a delay problem, because after the window is opened, the instruction setValue() works:

    http://www.electricblueskies.com/smeraldo/es02.html (see the button in the window)

    But... how can I solve my problem?

  9. #8
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    8,620
    Answers
    612
    Vote Rating
    397
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      1  

    Default


    This is a timing issue. In the forceSelection, you are required to find a value in the store. In the other instance you are not.

    You making an ajax call. It is most likely the incoming results are causing havoc.
    Code:
    type: 'ajax',
    url : 'storeCaratteristica.php',
    reader: {
    	type: 'json'
    }
    You can either load the table before hand, or make the update upon success of the ajax call.

    Scott.

  10. #9
    Sencha User
    Join Date
    Feb 2012
    Posts
    28
    Answers
    2
    Vote Rating
    1
    Dafram is on a distinguished road

      0  

    Default


    Thanks

  11. #10
    Sencha User
    Join Date
    Feb 2012
    Posts
    28
    Answers
    2
    Vote Rating
    1
    Dafram is on a distinguished road

      0  

    Default


    I have solved with this:

    Code:
            storeCaratteristica.on("load",onLoadCbCaratteristica);
            
            function onLoadCbCaratteristica()
            {
                    var_caratteristica = 1;
                    cbCaratteristica.reset();
                    cbCaratteristica.setValue(var_caratteristica);
            }
    Example: http://www.electricblueskies.com/smeraldo/es02.html

    But if in the form I have more than 1 store to wait to load, the problem returns...

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar