Announcement

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

    Converting Y/N to boolean for checkbox

    I'm using a legacy SQL table for a data source where there are single character columns used to store boolean values as "Y" or "N". I'd like to define a value map in the data source to convert them to/from a true boolean so they can be displayed as a checkbox, but I'm not sure how. I tried this based on what I saw in another post and it does render the field as a checkbox in my DynamicForm but I'm getting a validation error that says "Must be a true false value" when submitting the form.

    Code:
    <field name="InStore" type="boolean" title="In Store" detail="true">
    <valueMap>
          <true>Y</true>
          <false>N</false>
    </valueMap>

    #2
    That's not the right XML for a valueMap, see the samples (<value ID= ...)

    Comment


      #3
      I've also tried this, but I get a dropdown with choices "true" and "false" instead of a checkbox and when I submit I get the same error "Must be a true/false value"

      <valueMap>
      <value ID="Y">true</value>
      <value ID="N">false</value>
      </valueMap>

      Comment


        #4
        Still looking for the correct way to express this example from the documentation in the datasource XML.

        - More arbitrary data values can be resolved to checked / unchecked values via an object mapping the abitrary data values to display values of true and false. For example:
        {"A":false, "B":true}

        I've tried all of the variations I can think of and none work. What is the XML equivalent of {"N":false, "Y":true} ??

        Comment


          #5
          Not sure what I did to make it work, but it wasn't a problem with my valueMap syntax. In case anyone has a similar issue (how to convert datasource js example to xml) I came across a useful tip. Use the developer console to serialize a js datasource to XML, like this ...
          Code:
          isc.DataSource.get("DataSource").xmlSerialize(
          {ID :"testDS",
          fields : [{
          name: "legacyBool", title: "Legacy Boolean", 
          editorType: "Checkbox",
          valueMap : {
          "Y" : true,
          "N" : false
          }}]})
          That produces the following, which indicates that my data source was using the correct syntax after all. Still not sure what caused it to start working, but I'm happy it does.
          Code:
          <DataSource ID="testDS">
              <fields>
                  <field name="legacyBool" title="Legacy Boolean">
                      <valueMap>
                              <value id="Y">true</value>
                              <value id="N">false</value>
                      </valueMap>
                      <editorType>Checkbox</editorType>
                  </field>
              </fields>
          </DataSource>"

          Comment


            #6
            Note that you have to use the Developer Console *launched from Visual Builder* for that tip to work fully.

            Comment


              #7
              I just ran into the same error message ("Must be a true/false value"), even though my DynamicForm was carefully configured as per the documentation. What I only realized after some time: On the DataSource I had still defined the type: "boolean" which triggers a classical boolean validation (value must be true or false). The poster of this thread had also (initially) set the type to "boolean". Lesson learned: do not use type: "boolean" on a checkbox with a custom valueMap!

              Comment

              Working...
              X