Announcement

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

    CheckBox values

    I have need for a checkbox that uses 1 and 0 as values instead of true and false. I've defined the field in my datasource as type unsignedByte (instead of boolean, which causes the validator to complain) with an editor that is NativeCheckboxItem. There's nothing in the docs for either of the CheckboxItem implementations regarding setting the checked and unchecked values. CheckboxItem has a reference to setValueMap() but the only information is a warning about overriding it. I imagine the solution might involve defining a valueMap in the superclass FormItem, but I'm not sure what is required.

    Recommendations?

    #2
    Hi,
    There are 2 ways to achieve this using a valueMap on a CheckboxItem:
    For a simple case where one value evaluates to false (in JS), and the other to true (such as 0 and 1, or "someString" and null), you can use a simple 2 element array as the valueMap for the item - something ilke this:
    Code:
    DynamicForm.create({
        ... // various props
        fields:[
            {name:"fieldName", defaultValue:0, 
             editorType:"checkbox", valueMap:[0,1]},
            ...
        ]
    });
    For more arbitrary data values you can specify a valueMap on the CheckboxItem instance which has the javascript boolean values as display value, and the data values (in this case the numbers 0 and 1) be the "data" values for the field.

    So your checkbox item definition in the form might appear to be something like
    Code:
    DynamicForm.create({
        ... // various props
        fields:[
            {name:"fieldName", defaultValue:0, 
             editorType:"checkbox", valueMap:{0:false, 1:true}},
            ...
        ]
    });
    Will this work in your application?
    Let us know if you hit any problems with it.

    We'll also be sure to update our documentation to make the use of valueMaps with Checkboxes a little clearer.

    Thanks
    Isomorphic Software
    Last edited by Isomorphic; 2 Mar 2007, 09:47.

    Comment


      #3
      Is it possible to display a valuemap like how radio button value maps work but with checkboxes?

      For example below, I want to see two checkboxes, one with title "false" and another with title "true".

      Code:
      DynamicForm.create({
          fields:[
              {name:"fieldName", 
               editorType:"checkbox", valueMap:{0:false, 1:true}}
          ]
      });

      Comment


        #4
        No, CheckBoxItems are always singular, so you would need to use more than one CheckBoxItem to get this effect.

        Comment


          #5
          Just a thought, is it possible to override the look of a radio button to look like a checkbox item BUT only for certain cases such as mentioned above?

          Comment


            #6
            Not at the moment - you basically need to go with multiple CheckBoxItems to get more than one Checkbox.

            Comment

            Working...
            X