Results 1 to 8 of 8

Thread: SimpleComboBox<String> change listener in GXT 3

  1. #1
    Sencha User
    Join Date
    Jan 2010
    Location
    Moscow
    Posts
    27

    Default SimpleComboBox<String> change listener in GXT 3

    Hello!


    1 Q : how to set default value in SimpleComboBox<String> ?

    2 Q: How to add SimpleComboBox<String> change listener to change EmptyText in TextField ?
    PHP Code:

       
    List<String> list = GType.getNames(); // asList ("one","two");

      
    final   SimpleComboBox<StringgType = new SimpleComboBox<String>(new StringLabelProvider<String>());
     final    
    TextField text = new TextField();



    gType = new SimpleComboBox<String>(new StringLabelProvider<String>());
                
    gType .setId("gType" number);
                
    gType .setItemId("gType" number);
                
    gType .setName("gType" number);




                
    gType.setTriggerAction(ComboBoxCell.TriggerAction.ALL);
                
    gType.add(list);
                
    gType.setForceSelection(true);
                
    gType.setSelectOnFocus(true);
                
    gType.setEditable(false);
              
                
    //gType.setOriginalValue(list.get(0)); //not work!!! 1Q
                //gType.setValue(list.get(0)); //not work!!! 1Q

                  
    gType.select(0); // not work!!! 1Q


             
    gameType.addChangeHandler(new ChangeHandler() {
                    @
    Override
                    
    public void onChange(ChangeEvent event) {
                        
    int index gType.getSelectedIndex();
                        
    String name= list.get(index);
                        
    GType gType GType.fromModelName(name);
                        switch (
    gType) {
                            case 
    ONE:
                                
    text.setEmptyText("1");
                                break;
                            case 
    TWO:
                                
    text.setEmptyText("2");
                                break;
                        }
                    }
                }); 

  2. #2
    Sencha User
    Join Date
    Jan 2010
    Location
    Moscow
    Posts
    27

    Default

    UP

  3. #3
    Sencha Premium Member
    Join Date
    Aug 2012
    Posts
    49

    Default

    You would want to set the default using setValue rather than select.

    And you could use either SelectionHandler or ValueChangeHandler, depending on whether you want the text field changed before or after the user clicks out of the combobox.

  4. #4
    Sencha User
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    98
    Answers
    15

    Default

    Two points i will make here.
    You are setting value before adding change handler, that may be the reason the text field does not display the value..

    And also, you need to fire events while setting the value.

    Here is the code, working perfectly:
    Code:
    		SimpleComboBox<String> gType = new SimpleComboBox<String>(new StringLabelProvider<String>());
    		final    TextField text = new TextField();
    		List<String> list = new ArrayList<String>();
    		list.add("abc");
    		list.add("def");
    		list.add("ghi");
    		list.add("jkl");
    		
           gType.setTriggerAction(ComboBoxCell.TriggerAction.ALL);
           gType.add(list);
           gType.setForceSelection(true);
           gType.setSelectOnFocus(true);
         
    
    
           gType.addValueChangeHandler(new ValueChangeHandler<String>() {
     		
     		@Override
     		public void onValueChange(ValueChangeEvent<String> event) {
     			String val = event.getValue();
     			if(val.equalsIgnoreCase("abc"))
     				text.setEmptyText("ABC");
     			else if(val.equalsIgnoreCase("def"))
     				text.setEmptyText("DEF");
     			else
     				text.setEmptyText("OK");
     			
     		}
     	});
           
           gType.setValue(list.get(0),true);
    Any issue, please let me know.

  5. #5
    Sencha User
    Join Date
    Jan 2010
    Location
    Moscow
    Posts
    27

    Default

    Thx!

    but if I set gType.setValue(list.get(0),true);

    default value is empty


    PHP Code:
         SpinnerField<Integer>  multiplier 
                    new 
    SpinnerField<Integer>(new  NumberPropertyEditor.IntegerPropertyEditor());           

     
    multiplier.setId("multiplier" number);            multiplier.setItemId("multiplier" number);           

     
    multiplier.setName("multiplier" number);            multiplier.setMinValue(1);           

     
    multiplier.setMaxValue(100);            //multiplier.setValue(1, true, true);  not work!!!           

     
    multiplier.setValue(1,true);//  not work!!!             //multiplier.setOriginalValue(1); // not work!!! 

  6. #6
    Sencha User
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    98
    Answers
    15

    Default

    I did not get you. Default Value of what?
    Can you please clearly explain like you explained while posting the question.

  7. #7
    Sencha User
    Join Date
    Jan 2010
    Location
    Moscow
    Posts
    27

    Default

    Field in SpinnerField<Integer> multiplier is empty

    then I set value

    multiplier.setValue(1,true);// not work!!!







    SimpleComboBox<String> gType is empty to (then I set gameType.setValue(list.get(0),true)
    Attached Images Attached Images

  8. #8
    Sencha User
    Join Date
    Nov 2013
    Location
    Bangalore, India
    Posts
    98
    Answers
    15

    Default

    You are still not clear. You should clearly mention what is gType and gameType. The value of the fields depend on whose value gType or gameType.

    I assumed, gType and gameType both are simple combobox and you want to change value of gType, and both the fields with the value change in gameType.

    So, here is working code...

    Code:
            final SimpleComboBox<String> gType = new SimpleComboBox<String>(new StringLabelProvider<String>());
            SimpleComboBox<String> gameType = new SimpleComboBox<String>(new StringLabelProvider<String>());
    
    
            final SpinnerField<Integer> nf = new SpinnerField<Integer>(new  NumberPropertyEditor.IntegerPropertyEditor());
            final    TextField text = new TextField();
            List<String> list = new ArrayList<String>();
            list.add("abc");
            list.add("def");
            list.add("ghi");
            list.add("jkl");
            
            final List<String> list2 = new ArrayList<String>();
            list2.add("aaa");
            list2.add("bbb");
            list2.add("ccc");
            list2.add("ddd");
            
            
            gameType.setTriggerAction(ComboBoxCell.TriggerAction.ALL);
            gameType.add(list);
            gameType.setForceSelection(true);
            gameType.setSelectOnFocus(true);
         
           
            gameType.addValueChangeHandler(new ValueChangeHandler<String>() {
             
             @Override
             public void onValueChange(ValueChangeEvent<String> event) {
                 String val = event.getValue();
                 if(val.equalsIgnoreCase("abc")){
                     text.setEmptyText("ABC");
                     nf.setValue(1);
                     gType.setValue(list2.get(0));
                 }
                 else if(val.equalsIgnoreCase("def")){
                     text.setEmptyText("DEF");
                     nf.setValue(2);
                     gType.setValue(list2.get(1));
                 }
                 else{
                     text.setEmptyText("OK");
                     nf.setValue(3);
                     gType.setValue(list2.get(3));
                 }
             }
         });
           
           gameType.setValue(list.get(2),true);
           gameType.setEditable(false);

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
  •