Announcement

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

    SelectItem with multiple="true - add support for comma-separated string

    Hi Isomorphic,

    I work with the latest build (v12.1p_2020-06-20) and trying to have a SelectItem with multple="true" that supports
    getting and storing its data as comma-seprataed string, instead of an array which is the default behavior.

    This is a working example, that only supports setting the item value with a string: mySelect.setValue("US,JA")
    I didn't manage to have its value also stored as a string.
    I tried overriding setValue\storeValue functions, but this broke the control's functionality.

    Based on https://www.smartclient.com/smartcli...ocalDataSource
    with these modifications:

    Code:
    isc.DynamicForm.create({
        ID:"exampleForm",
        width:450,
        wrapItemTitles: false,
        fields: [
            {
                ID: "mySelect",
                name: "mySelect",
                type:"select",
                title:"Select Multiple (PickList)",
                multiple:true,
                multipleAppearance:"picklist",
                valueField: "countryCode",
                displayField: "countryName", 
                optionDataSource: "countryDS",
                setValue: function (newValue){
                  if (isc.isA.String(newValue)) newValue=newValue.split(","); 
                  this.Super("setValue",[newValue]);
    
                }
            },
        ]
    });
    
    
    mySelect.setValue("US,JA");
    Could you please guide me on how to have the stored value to be a string as well?
    (in my example, I would expect it to be "US,JA")

    #2
    You should set the .ds.xml field as multiple="true" as well. You can't do that in the SmartGWT showcase, but perhaps in the SmartClient one with a clientOnly DataSource - or in your own project.

    Comment


      #3
      Hi Blama , thanks for your reply!

      I based my question on the local DS (client only) example.
      I tried to add multiple: "true" as you suggested but it didn't help. The value is still stored as an array

      I tried setting "multiple" property to countryCode\countryName fields, with\without quotation marks,
      even tried to set it to false - none of that worked.

      Code:
      isc.DataSource.create({
          ID: "countryDS",
          fields:[
              {name:"countryCode", title:"Code", multiple:"true"},
              {name:"countryName", title:"Country"},
              {name:"capital", title:"Capital"}
          ],
          clientOnly: true,
          testData: countryData
      })
      Any other idea?

      Comment


        #4
        Hi,

        what do you mean by String? "US,JA" is a String. If you wanted "United States,Japan" (and also set it like this, change the valueField.

        Code:
        isc.DynamicForm.create({
            ID:"exampleForm",
            width:450,
            wrapItemTitles: false,
            fields: [
                {
                    ID: "mySelect",
                    name: "mySelect",
                    type:"select",
                    title:"Select Multiple (PickList)",
                    multiple:true,
                    multipleAppearance:"picklist",
        [B]valueField: "countryName",[/B]
                    displayField: "countryName", 
                    optionDataSource: "countryDS",
                    setValue: function (newValue){
                      if (isc.isA.String(newValue)) newValue=newValue.split(","); 
                      this.Super("setValue",[newValue]);
        
                    }
                },
            ]
        });
        
        
        mySelect.setValue("United States,Japan");
        isc.logWarn(exampleForm.getValue("mySelect"));
        Does that help?

        Best regards
        Blama

        Comment


          #5
          Hi Blama ,
          Thanks again for your patience and your willingness to help.


          No, I don't mean to set the valueField to "countryName".
          All I want is that when we try to get the value from the select item (like you did here: exampleForm.getValue("mySelect")),
          it will also return "US,JA" as a string.

          In your example, it returns an array ["United States", "Japan"], which is not what I want.
          I tried all sorts of things to resolve it, like I mentioned in my original post - including overriding getValue function, but it always breaks the control's functionality.



          I hope it's more clear now.

          Kobi

          Comment


            #6
            On the server, we offer dataSourceField.multipleStorage as a way to store as a comma-separated string, because this then gives you round-trip storage to a SQL column.

            We can't imagine a point to offering this functionality on the client. It's incredibly trivial to interconvert between an array and comma separated string (join(') and split(')).. it took far longer to describe and discuss the need than to simply solve it ... ?

            Comment

            Working...
            X