Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Styled entries from DataSource XML

    Hi,

    I came across the following issue: when adding styled entries via the datasource descriptor, the values appear styled in the dropdown list...
    but when selecting a value from the list, I get the value with the HTML tags instead of the "applied" styled value (see screenshot).

    After some investigation, I found out that the issue can be traced to the use of the comboBoxItem (iso the selectItem as in the showcase example).
    http://www.smartclient.com/smartgwt/...bobox_category

    I have added a standalone test case below.

    Code:
    public class Standalone implements EntryPoint {
    	
    	private static Canvas masterPanel = null;
    	
    	/**
    	 * TEST CASE 4: styled ComboBoxItem
    	 * 
    	 * 
    	 * @sofhistory
    	 * 24-feb-2011	bade	initial version
    	 * 
    	 * @see com.google.gwt.core.client.EntryPoint#onModuleLoad()
    	 *
    	 */
    	 public void onModuleLoad() {  
    	 		
    		//masterPanel should be a Layout
    		masterPanel = new Canvas(); 
    		masterPanel.setHeight100();
    		masterPanel.setWidth100();
    		masterPanel.setStyleName("pageBackground"); //background style from skin
    		
    		ComboBoxItem comboBox = new ComboBoxItem();   
            comboBox.setTitle("Select");   
            comboBox.setHint("<nobr>A ComboBox with styled entries</nobr>"); 
            	        
            LinkedHashMap<String, String> valueMap = new LinkedHashMap<String, String>();
            valueMap.put("1", "<span style='color:#FF0000;'>Red</span>");
            valueMap.put("2", "<span style='color:#00FF00;'>Green</span>");
            valueMap.put("3", "<span style='color:#0000FF;'>Blue</span>");	        
            comboBox.setValueMap(valueMap);
    
            //the order list grid   
    	    DynamicForm form = new DynamicForm();   
    	    form.setHeight(170);   
    	    form.setWidth(500);
    	    
    	    form.setFields(comboBox);
    	
    		masterPanel.addChild(form);
    		masterPanel.draw();	
    	}
    }
    Attached Files
    Last edited by bade; 8 Mar 2011, 06:27.

    #2
    You need to separate styling from data. With the information provided, the ComboBoxItem will necessarily think that eg "span" of "FF00" should complete to one of the values. You can instead apply styling via pickListFields and pickListProperties.

    Comment


      #3
      I'm sorry, but I don't understand why a SelectItem is doing this fine, while a ComBoBoxItem is not.
      Independent of the fact that you need to seperate styling from data.

      I'm also trying out your suggestion of using the pickListProperties... but I get the feeling that doesn't work that well with a valueMap.
      All examples use an optionDataSource.

      From the showcase:

      Code:
               SelectItem selectItem2 = new SelectItem();  
               selectItem2.setTitle("Select");  
               selectItem2.setHint("<nobr>A SelectItem with styled entries</nobr>");  
               selectItem2.setValueMap("<span style='color:#FF0000;'>Red</span>",  
                       "<span style='color:#00FF00;'>Green</span>",  
                       "<span style='color:#0000FF;'>Blue</span>");
      Last edited by bade; 9 Mar 2011, 04:21.

      Comment


        #4
        It's technically bad practice with a SelectItem too, it's just more obvious that there's a problem with a ComboBoxItem that has autocomplete. With a SelectItem, the drawbacks are still there (eg can't correctly select an item by typing the first letter) but may be acceptable.

        Comment

        Working...
        X