Announcement

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

    Display selected key in SelectItem textbox

    Hello,
    For SmartGwt 6.0p , Chrome, Firefox, etc .
    I have a multiple-select SelectItem working as-advertized, however I want to display the key of the valueMap (not the value) in the textBox that is part of the widget.
    The value is long text, but the key is short text, and that's what we need to display in the box.

    E.g.,

    daysPickList = new SelectItem();
    daysPickList.setTitle("Select Days");
    daysPickList.setMultiple(true);
    daysPickList.setMultipleAppearance(MultipleAppearance.PICKLIST);
    daysPickList.setValueMap(daysValueMap);
    daysPickList.setDefaultToFirstOption(true);

    where daysValueMap =
    daysValueMap = new LinkedHashMap<String, String>();
    daysValueMap.put("All", "Select All Days");
    daysValueMap.put("M", "Monday");
    daysValueMap.put("T", "Tuesday");
    daysValueMap.put("W", "Wednesday");
    daysValueMap.put("TH", "Thursday");

    What's the tonic to displaying the selected key in the textBox? (M,T,W...)

    Thanks
    -Tom

    #2
    Use setValueFormatter().

    Comment


      #3
      This us difficult to explain. Unfortunately, setValueFormatter is not what I'm after. That will set the values in the drop-down list. I want to format the values that are listed horizontally as items are selected.
      The drop-down shows [Monday, Tuesday, Wednesday, Thursday] , which is correct, I want the shown values printed to be [M,T,W,Th] (which ever are checked).
      See attached screenshot. I want "T,Th" to be listed horizontally, not the long format "Tuesday, Thursday"
      Attached Files
      Last edited by thomlep; 26 Oct 2016, 11:22.

      Comment


        #4
        Yes, this is what we understood that you wanted to do, and setValueFormatter() can be used for this purpose. There's an example here showing how it can be used.

        Comment


          #5
          I'll try again.. That code in the example does not seem to match the compiled example. Also, I'm using a Map<String,String> , not a ListGrid.
          I appreciate your help. Maybe I'll try a ListGrid and make one field hidden, and not show header.
          Last edited by thomlep; 26 Oct 2016, 12:15.

          Comment


            #6
            That sample doesn't show a ListGrid - we have no idea what your comments mean. Yes, trying again definitely make sense.

            Comment


              #7
              The lower comboBox here is close to what we need: http://www.smartclient.com/smartgwt/...bobox_category . Looks like the trick is to use a ListGridField
              Last edited by thomlep; 26 Oct 2016, 12:24.

              Comment


                #8
                Just FYI, the code you have in the example http://www.smartclient.com/smartgwt/..._related_value does not match the compiled version that you have. You have
                ...
                ...
                return r.getAttribute("Name") + " (" + r.getAttribute("Email") + ")";

                but the running example displays just the name attribute. That's what I mean.

                Comment


                  #9
                  The email is shown on blur. This is by design, as you don't want it cluttering your search box if you're going to modify the search term.

                  Comment


                    #10
                    I have been able to to confirm that "Use setValueFormatter(). " does not work. I don't want the drop-down items changed, just the items displayed horizontally.

                    This code confirms that "Use setValueFormatter(). " does not work.

                    daysPickList = new SelectItem();
                    daysPickList.setTitle("Select Days");
                    daysPickList.setMultiple(true);
                    daysPickList.setMultipleAppearance(MultipleAppearance.PICKLIST);
                    daysPickList.setValueMap(daysValueMap);
                    daysPickList.setDefaultToFirstOption(true);

                    daysPickList.setValueFormatter(new FormItemValueFormatter() {

                    @Override
                    public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
                    return "foo";
                    }
                    });


                    Last edited by thomlep; 27 Oct 2016, 10:56.

                    Comment


                      #11
                      See screenshot. setValueFormatter() is formatting the items in the dropdown. Not what's wanted. I only want the items in the horizontal list formatted.
                      Attached Files

                      Comment


                        #12
                        Sorry for the confusion here.
                        What you're looking for is a slightly unusual use case - the formatting (or valueMap) specified on a SelectItem will typically be applied to both the entries in the drop down picklist and to the value displayed in the text-box area. To show different values in the drop down you can customize the pickList via setPickListProperties and/or setPickListFields.

                        In this case the easiest way to get what you want would be to specify the valueMap for the item as a simple array (this sets up the list of options that are available), and then use a customized pickListFields attribute to modify how these options are displayed in the drop down. Here's a simple test case demonstrating this. Note that the "name" of the pickListField that is shown matches the name of the item itself, and the values are being formatted via a valueMap applied directly to the field. You could also use a custom cellFormatter on the field if you wanted dynamic rather than static formatting applied to the values in the drop down.

                        Code:
                             public void onModuleLoad() {
                                  String[] daysVM = {
                                          "All",
                                          "M",
                                          "T",
                                          "W",
                                          "TH"};
                           
                                  LinkedHashMap<String, String> plDaysVM = new LinkedHashMap<String, String>();
                                  plDaysVM.put("All", "Select All Days");
                                  plDaysVM.put("M", "Monday");
                                  plDaysVM.put("T", "Tuesday");
                                  plDaysVM.put("W", "Wednesday");
                                  plDaysVM.put("TH", "Thursday");
                                  
                                  ListGridField plDays = new ListGridField("days");
                                  plDays.setValueMap(plDaysVM);
                           
                                  SelectItem days = new SelectItem("days");
                                  days.setTitle("Select Days");
                                  days.setMultiple(true);
                                  days.setMultipleAppearance(MultipleAppearance.PICKLIST);
                                  days.setValueMap(daysVM);
                                  days.setDefaultToFirstOption(true);
                                  days.setPickListFields(plDays);
                                  
                                  DynamicForm testForm = new DynamicForm();
                                  testForm.setFields(days);
                                  testForm.draw();
                              }
                        Regards
                        Isomorphic Software

                        Comment

                        Working...
                        X