Announcement

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

    Calling setEditorType(new CheckboxItem()) on Text field

    For argument's sake, assume I have a 'text' field that contains either a 'true' or 'false' value. I need to represent the string value with a CheckboxItem, and I cannot change the field definition to type='boolean'.

    Mostly, this "just works" if I setEditorType. The problem I seem to have is that when the CheckboxItem is rendered, it is always checked.

    So if I'm editing a grid record with a field value of "false", the field's editor is opened with my item checked. If I click the checkbox once, the box remains checked and the underlying value is set to true - which is of course correct. Click again to uncheck and set the value to false - also correct. Just that initial state is a problem. Bug?

    Here's a little testcase, run with 3.1d20121004 on Firefox 15.1

    Code:
    <DataSource ID="ClientOnly"
      clientOnly="true"
      dataURL="/ds/data/CLientOnly.xml">
        
        <fields>
            <field name="id" title="ID" type="int" primaryKey="true"/>
            <field name="value" title="Value" type="text" length="3000"/>
        </fields>
    
    </DataSource>
    Code:
    <List>
        <ClientOnly>
            <id>1</id>
            <value>false</value>
        </ClientOnly>
    </List>
    Code:
    	public void onModuleLoad() {
    		
    		ListGrid grid = new ListGrid();
    		
    		grid.setDataSource(DataSource.get("ClientOnly"));
    		grid.setUseAllDataSourceFields(true);
    		grid.setAutoFetchData(true);
    		grid.setCanEdit(true);
    
    		ListGridField value = new ListGridField("value");
    		value.setEditorType(new CheckboxItem());
    		
    		grid.setFields(value);
    		
    		VLayout layout = new VLayout();
    		layout.setWidth100();
    		layout.setHeight100();
    		
    		layout.addMember(grid);
    		
    		layout.draw();
    
    		if (!GWT.isScript()) {
    			KeyIdentifier debugKey = new KeyIdentifier();
    			debugKey.setCtrlKey(true);
    			debugKey.setAltKey(true);
    			debugKey.setKeyName("D");
    			Page.registerKey(debugKey, new KeyCallback() {
    				public void execute(String keyName) {
    					SC.showConsole();
    				}
    			});
    		}
    	}
    Last edited by bbruyn; 10 Oct 2012, 15:21.

    #2
    The problem is that the string "false" evaluates to boolean value equivalent of true in JavaScript - try a conditional like
    var foo = "false"; if (foo) alert(1);
    to see what we mean!

    You should be able to resolve this by applying a valueMap to the item, specifying a map mapping the strings to the equivalent booleans -- essentially {true:true, false:false}.

    Will this work for you?

    Comment


      #3
      Bah. Been a long time since I've been bitten by that. The valueMap approach is working just fine. Thanks for the hand, as always.

      Comment

      Working...
      X