Announcement

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

    Is there a way to disable options in a SelectItem?

    Hi,

    We've got a SelectItem that is populated with enum values. Is it possible to disable one or more options in the list without actually removing it from the ValueMap?

    The scenario is like this:
    - We've got an invoice which "type" is set "undefined" programmatically when an invoice is created on the server side.
    - The user needs to select a new type for the invoice from the SelectItem.
    - He should be able to select all values, except "undefined", but he should also be able to see that it is currently "undefined"

    If we remove "undefined" from the underlying ValueMap the user gets an ugly UNDEFINED text in the SelectItem.
    If we do not remove it, we can't seem to find a way to easily disable that value in the UI.

    Best regards
    Kimf

    ---

    Using SmartGWT 2.5 Pro.

    #2
    I'm also trying to find a way to do so.
    If somebody got an idea, it would be nice :-)

    Comment


      #3
      I too am most interested in how this can be achieved. Also, is it possible to remove a value if you are generating values via an Java Enum?

      Comment


        #4
        You do this via providing an optionDataSource, which allows you to use pickListProperties and pickListFields to get the same control over the options that you have with ListGridRecords, including setting some as disabled.

        If you already have the data as a valueMap, just convert it to a set of Records and make a clientOnly:true optionDataSource.

        Comment


          #5
          Getting at the data with this concept is proving difficult- I cannot get the record list to be able to iterate them and disable/enaable based on changes in the application. For example: In the particular form I'm working in, if a user chooses some other option, certain values in the SelectItem need to be disabled.

          Code:
          siResolution = new SelectItem("pixelWidthHeight");
                  resolutionList = new ListGrid();
                  resolutionList.setAutoFitData(Autofit.HORIZONTAL);
                  resolutionList.setDataFetchMode(FetchMode.BASIC);
                  siResolution.setPickListProperties(resolutionList);
          
                  siResolution.setOptionDataSource(GSUI.getResolutionLookupDS());
                  siResolution.setValueField("id");
                  siResolution.setDisplayField("resolutionDimensions");
                  siResolution.setTitle("Size");
                  siResolution.setAutoFetchData(true);
          Iteration code: problem is that the call to resolutionList.getRecords() returns 0.

          Code:
          if(someCondition)
                          {
                              //we have to limit the number of resolutions we can use
                              siResolution.setDisabled(false);
                              for(ListGridRecord resolution : resolutionList.getRecords())
                              {
                                  String resolutionDimensions = resolution.getAttribute("resolutionDimensions").toString();
                                  if(resolutionDimensions.equals("1024x768") || resolutionDimensions.equals("1600x900"))
                                  {
                                      resolution.setEnabled(false);
                                  }
                              }
                          }

          Comment


            #6
            "resolutionList" is just a set of properties passed to configure the PickList. It does not somehow become the picklist. Two ways to get the data are the DataArrived event, or transformResponse at the DataSource level.

            If you're using a clientOnly DataSource, you can also just replace the dataset (setCacheData()) then call fetchData() on the SelectItem.

            Comment


              #7
              Thank you for your help.
              Works fine

              Comment


                #8
                I might be missing something here, so I'll explain my use case with more detail:

                I have a DynamicForm which has three SelectItems. Two are populated by the form's datasource. A third is populated with an optionDataSource.

                When a user changes a value in one of the SelectItmes the SelectItem populated by the optionsDataSource needs to be adjusted.

                For example: If a user chooses a certain option (Video Type), the other select item needs to allow or disallow selection of its options based on the video type choice. To further demonstrate- if a user chooses Video Type "A", then the SelectItem containing the possible resolutions for that video stream need to be 640x480, 1280x1024, and 1920x1280. If the user chooses Video Type "B", then several more resolution options become available for selection.

                I'm working under the impression that since I'm using a ListGrid as the component in the resolution SelectItem, I can somehow enable and disable certain rows/records programmatically.

                Because these are not dependent on a dataArrivedEvent (these actions all take place after that), I'm not sure how to make this happen given the advice you gave.

                Any help in the right direction is appreciated.

                Thanks,

                Comment


                  #9
                  Perhaps something like this: siResolution.getClientPickListData()[0].setEnabled(false); However I can still select this option in the SelectItem after setting the ListGridItem to enabled(false);
                  Last edited by ls3674; 26 Apr 2012, 14:30.

                  Comment


                    #10
                    Wow, really? Insightful.

                    Comment


                      #11
                      Sorry about the spam message - we've removed it.

                      Assuming the list of resolutions is loading from a dataSource: is your optionDataSource (with the resolutions) a client-only dataSource, or is it loading data from the server?
                      If a client-only dataSource the "setCacheData()" approach should work for you.

                      getClientPickListData() is probably not what you want - that doesn't really apply when the SelectItem is picking up data from an optionDataSource.

                      It might also be helpful to show us a code snippet so we are sure we really follow your use case -- basically the definitions for the 3 items plus the associated datasource declarations.

                      Comment

                      Working...
                      X