Results 1 to 8 of 8

Thread: Get combobox value

  1. #1
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    40
    Answers
    2

    Default Get combobox value

    Hi, I've got a combobox like this:
    Code:
    xtype: 'combobox',
    editable: false,
    queryMode: 'local',
    store: [ [1,'label 1'], [2,'label 2'] ]
    And I have comboboxes like that on my project that works fine. But this combobox returns the valuefield ('label 1') when I do a getValue() instead of returning the valuefield (1).

    I tryed to create an arraystore like the documentation but anything change.

    Its odd because recreating it on the fiddle, doesnt act like the real execution.

    How can the combobox return the correct value?

  2. #2
    Sencha User
    Join Date
    Apr 2013
    Posts
    913
    Answers
    105

    Default

    Use valueField and displayField to specify which field supposed to represent what.

  3. #3
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    40
    Answers
    2

    Default

    It makes no difference.

  4. #4

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    40
    Answers
    2

    Default

    There's something that I have skipped, when I define the store, I do not write directly the string 'label 1', that string is returned by a function.

    My code is like this:

    Code:
    xtype: 'combobox',
    editable: false,
    queryMode: 'local',
    store: [ [1, getLabelText() ], [2, getLabelText()] ]


    If I change to a raw string, it works fine, but I need to do that beacuse the string might change.

  6. #6
    Sencha User
    Join Date
    Apr 2013
    Posts
    913
    Answers
    105

    Default

    Make sure your functions are actually defined in that context.

  7. #7
    Sencha Premium Member
    Join Date
    Apr 2015
    Posts
    40
    Answers
    2

    Default

    They are globaly declared and searching the content of the store on the console, data are correct ( field1: 1, field2: 'label 1' ).

    Declaring the store with raw strings works perfectly, but if I put there a function, the getValue() returns the displayField.

    I can retrieve the valueField by doing this:

    index = combobox.getStore().find( 'field2', combobox.getValue() );
    valueField = combobox.getStore().getRange()[ index ].get('field1');



    But i'm searching for the traditional and less code way. Thanks for your interest.

  8. #8
    Sencha User
    Join Date
    Apr 2013
    Posts
    913
    Answers
    105

    Default

    There seems to be a bug in 6.0.2 which causes wrong value to be returned when your string starts with a newline:
    https://fiddle.sencha.com/#fiddle/1imr
    If that's the issue you are facing, try to trim the value before returning in your function.
    The bug seems to be fixed in 6.2 .

Similar Threads

  1. Replies: 4
    Last Post: 17 Jun 2016, 7:01 AM
  2. [CLOSED] Data binding on cell editing combobox works, but fails on widget combobox
    By Necro-Engineering in forum Ext JS 6.x Bugs
    Replies: 3
    Last Post: 10 Jan 2016, 2:09 PM
  3. Replies: 5
    Last Post: 17 Nov 2014, 7:04 AM
  4. Replies: 3
    Last Post: 6 Sep 2010, 12:36 PM
  5. Replies: 10
    Last Post: 17 Apr 2009, 12:30 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •