Announcement

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

    FormItem dataPath

    Hello,
    I am creating a DynamicForm to edit a nested data structure. Every item has a dataPath and a dynamically generated name. (I actually do not need name - without it validation marks all form items as incorrect). However, TextItem behaves strangely here and when I get all form values using getValues() (let's say vals), I get two same values, one vals[textItemName] and one vals[textItemDataPath]. SelectItem publishes its value only under dataPath. I don't know whether this behaviour is correct or not - docs say nothing about it.

    Code:
    DynamicForm.create({
      ID: "form1",
      items: [
        { type: "text", name: "n1", dataPath: "some/path1" },
        { type: "select", name: "n2", dataPath: "some/path2", valueMap: [1, 2, 3] }
      ]
    });
    
    /*
    form1.getValues():
    {
      some: {
        path1: "abc",
        path2: 3
      },
      n1: "abc"
    }
    */
    By the way, do you plan to install some sort of bug tracker?

    #2
    When you're using dataPath, name is optional. But if you specify a name and dataPath, you'll get exactly what your seeing - that data being double-represented under the name and the dataPath.

    The issue tracker on the Google Code site is where to file bugs if you have not purchased commercial support (and sometimes even if you have). However, please do not file bugs until it has been confirmed as a bug on the forums.

    Comment


      #3
      If I do not set item names:
      1) Validation fails on all fields with same error if at least one field is incorrect. (Some JS error is show in Firebug).
      2) Try this:
      Code:
      DynamicForm.create({
        ID: "form1",
        items: [
          { type: "integer", title: "A", dataPath: "some/path1" },
          { type: "select", title: "B", dataPath: "some/path2", valueMap: [1, 2, 3] },
          { type: "button", title: "Show values", click: "isc.say(isc.JSON.encode(form.getValidatedValues()).asHTML())" }
        ]
      });
      
      /*
      form1.getValidatedValues():
      {
        "some": {
          "path1": "1324", // value under dataPath is string
          "path2": 3
        },
        "undefined": 1324 // value under "undefined" is integer!
      }
      */
      Last edited by marpetr; 14 Jun 2010, 23:27.

      Comment


        #4
        What exact version are you using (check in the lower left hand of the Developer Console)?

        What is the JS error (please obtain a stack trace from the Developer Console in IE for any reported JavaScript error)?

        What validation errors are shown? (exact error messages).

        Comment


          #5
          Updated to the latest nightly (2010-06-15), now JS error is gone.
          For example if I enter "a1" in integer field, I get "Must be a whole number." error on all fields including button! If I enter a correct number, the item saves its value under "undefined" as integer and under "some/path1" as string.

          Comment


            #6
            Thanks for the update.
            We've checked in a change which should address this - try with the next nightly build and let us know if you're still seeing problems

            Thanks
            Isomorphic Software

            Comment


              #7
              Thank you for the fix. However, when form.getItem('...').validate() is called and validation fails, the errors are shown for every item. And shouldn't integer item save its value as integer?

              Here is an updated test case:
              Code:
              DynamicForm.create({
                ID: "form1",
                items: [
                  { type: "integer", title: "Integer item", dataPath: "some/path1" },
                  { type: "button", title: "Validate", click: "form.getItem('some/path1').validate()" },
                  { type: "button", title: "Show values", click: "isc.say(isc.JSON.encode(form.getValidatedValues()).asHTML())" }
                ]
              });
              By the way, you could replace name by dataPath, they would have identical behaviour (unless slashes are used) I think.
              And is there a way to force getValues() return ALL items' values? (Not only those which had their value ever modified).
              Last edited by marpetr; 18 Jun 2010, 05:49.

              Comment


                #8
                Aha - we fixed form.validate() but not formItem.validate()
                We've now made that change. Also you should see the value come back as an integer rather than a string now.

                In terms of getting an explicit 'null' back for form items with no default value when you call getValues(), you can always initialize your form with an object that specifies explicit values for your fields -- for example
                Code:
                isc.DynamicForm.create({
                  ID: "form1",
                  values:{some:{path:null}},
                  items: [
                    { type: "integer", defaultValue:"", title: "Integer item", dataPath: "some/path1" },
                    { type: "button", title: "Validate", click: "form.getItem('some/path1').validate()" },
                    { type: "button", title: "Show values", click: "alert(isc.Comm.serialize(form.getValidatedValues()))" }
                  ]
                });

                Comment

                Working...
                X