Announcement

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

    Dynamically addind valueMap to a formItem

    Trying to add a valueMap dynamically through the formItem method. It works fine - but it displays items as [object Object]. Did I pass the array format wrong?

    <code>
    var myForm= isc.DynamicForm.create({
    width: 500,
    numCols: 4,
    fields : [{
    name: "bugStatus", title: "Bug Status",
    editorType: "comboBox"}]
    });



    var field = myForm.getField("bugStatus") ;
    field.setValueMap( [ {"new" : "New"},{"active" : "Active"}] ) ;
    </code>

    #2
    Hi Gomathy,

    The format for a valueMap is
    Code:
        { new : "New",
           active : "Active" }
    If you are dynamically loading the data for the valueMap, consider comboBoxItem.optionDataSource instead.

    Comment


      #3
      Will you please let me know why the format is changed when it needs to be added dynamically. i.e if it will be provide during init - it is provided as:

      <code>
      valueMap : {
      "{new-25653@@AF#12}" : "New",
      "{active-25653@@AF#12}" : "Active"
      }

      </code>
      In eg: http://www.smartclient.com/index.jsp...t#listComboBox
      which provides the option of Value containing special characters.

      But in the format what is specifed as reply to the thread - it cannot be done.
      Further my requirement is - I have a json array which will need to be added after initialization. Will not use datasource for it.

      Will you let me know the way to do it please.

      Comment


        #4
        Hi Gomathy,
        There are 2 supported formats for valueMaps. One is a simple array of (string) values, like this:
        Code:
        ["value 1", "value 2", "value 3"]
        In this case each option in the array will be displayed to the user, and when the user selects an option it will become the value for the item.

        The other format is a javascript object mapping a data value (to be stored on the server) to a display value (to show to the user when they are making the selection). Something like this:

        Code:
        {new:"New", active:"Active"}
        In your original post, the problem was that your valueMap was an array of 2 options, and each option was a Javascript object rather than a string. This means the user would see 2 options to choose from, and each one would be a javascript object, natively converted to a string - which would render out as "[object Object]" or similar.
        Instead of this we believe you were trying to use map the data value "new" to the display value "New" and the data value "active" to the display value Active -- which you can achieve using an object rather than an array, as shown above.

        The setValueMap() method accepts exactly the same formats as the initial 'valueMap' property

        Special characters and attribute-name quoting:
        When defining a javascript object, the attribute names do not typically need to be quoted, but may be. In other words
        Code:
        {"new":"New", "active":"Active"}
        is equivalent to
        Code:
        {new:"New", active:"Active"}
        Also javascript is not strict about what characters are included in an attribute name, but, as you observe below you must quote the attribute name if you're going to include special characters - for example
        Code:
        {"{new-25653@@AF#12}" : "New",
                "{active-25653@@AF#12}" : "Active"}
        Therefore the above should be acceptable as an initial valueMap for an item as well as as the valueMap passed into setValueMap()
        One thing to note: If you are working with an object like the one above in JS, you will never be able to retrieve values from this object by standard 'dot notation' property access. For example this would result in a Javascript error:
        Code:
        alert(myObject.{new-25653@@AF#12});
        Instead you will have to quote the attribute name and use square-bracket notation to access it - like this
        Code:
        alert(myObject["{new-25653@@AF#12}"]);
        Regards
        Isomorphic Software

        Comment


          #5
          Thanks !! I misinterpreted & have posted question again - as I checked the format as an object, without eval(). Now it works fine !!

          Comment


            #6
            Sorry Isomorphic I would know if is possible set some value selected, i'm using:
            type:select multiple:true valueMap:{"0":"New", "1":"Active"}
            is possible have the Value Active enabled at loading time?

            Comment


              #7
              I'd like to obtain something like the image below

              Click image for larger version

Name:	Untitled.png
Views:	245
Size:	4.5 KB
ID:	240240

              Comment


                #8
                did you try defaultValue ?

                Comment


                  #9
                  yes, but doesn't work

                  Comment


                    #10

                    'defaultValue':'0'

                    but nothing is selected

                    Comment


                      #11
                      You'll have to post SmartClient version, browser and a test case.

                      For instance this is working in the showcase:
                      Code:
                      isc.DynamicForm.create({
                          ID:"exampleForm",
                          width:450,
                          fields: [
                              {
                                  type:"select",
                                  title:"Select Multiple (PickList)",
                                  multiple:true,
                                  multipleAppearance:"picklist",defaultValue:"Cat",
                                  valueMap: [ "Cat", "Dog", "Giraffe", "Goat", "Marmoset", "Mouse" ]
                              }
                          ]
                      });

                      Comment


                        #12
                        sc ver is 11.0
                        Chrome 53

                        here is my code:

                        isc.DynamicForm.create({
                        "width":"100%",
                        "ID":"pkl_48",
                        "height":30,
                        "fields":[{
                        "multiple":"true",
                        "name":"pkl_48",
                        "title":"iniMasterId",
                        "multipleAppearance":"picklist",
                        "defaultValue":"0",
                        "changed":"manageSelect({'form':'getDetail', 'widget':'iniMasterId', 'newValue': pkl_48.getValue('pkl_48')}, 'Relation')",
                        "value":"4, 5, 6",
                        "height":30,
                        "width":"100%",
                        "valueMap":{'1': 'Active', '0': 'New', '3': 'Dog', '2': 'Cat', '5': 'Goat', '4': 'Giraffe', '7': 'Mouse', '6': 'Marmoset'},
                        "type":"select"
                        }]
                        });
                        Last edited by peppicus; 15 Sep 2016, 22:29.

                        Comment


                          #13
                          Don't set "value".

                          Comment


                            #14
                            ok,
                            when i remove value it works, but with one only value.
                            "defaultValue":"0" // this works

                            If i need to set multiple values?
                            "defaultValue":"0, 4, 5" // this doesn't works
                            probably i'm applying a wrong syntax?

                            Comment


                              #15
                              sorry, i founded:
                              "defaultValue":[0, 4, 5] // this works

                              Tnks a lot!

                              Comment

                              Working...
                              X