Announcement

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

    SelectItem has empty value

    Hi,
    We are using smartgwt version 6.1-p20200204. We have a selectItem which shows first value as empty. We populate selectItem using valueMap.
    I tried using AllowEmptyValues as false but it didn't worked.

    Thanks

    #2
    Use setValue() to establish an initial value.

    Comment


      #3
      I am using setValue() to set initial value. It shows the value as set. Still if we click to open dropdown it show first value as empty.

      Thanks

      Comment


        #4
        The property is working as documented in a brief test. Perhaps you tried to set “allowEmptyValues” instead of the actual property name “allowEmptyValue” (no “S” at the end).

        Comment


          #5
          Hi,
          I used the "allowEmptyValue" field of SelectItem, I don't see any “allowEmptyValues” api.

          Thanks

          Comment


            #6
            Good. So, if you modify any of our samples - for instance “Various Controls” - to add the allowEmptyValue property, then you will see it functioning as documented.

            If you can show us a minimal, ready-to-run sample where the property is not behaving as documented, we would love to see it and correct any such bug as soon as possible.

            Comment


              #7
              Actually,
              We have a requirement to change select items value every 5 minutes. So, every five minutes i am changing value via setValue() and thats when its creating problems and shows first value in dropdown as empty. From initial load to first change in its value , the dropdown looks fine, but after first setValue() it looks bad with first value empty.

              Tell me if this clears things, other wise i will share a use case.

              Thanks

              Comment


                #8
                Unless you are calling setValue() with an empty value, this still does not create a problem, so we will need a minimal, ready-to-run test case that reproduces the claimed issue.

                Comment


                  #9
                  Hi,
                  Please find the ready to run use case:

                  //SelectItem creation
                  private SelectItem brandSelectItem = new SelectItem("BrandsName","BrandsTitle");

                  LinkedHashMap<String, String> valueMap = new LinkedHashMap<>();
                  valueMap.put("01", "ABrand");
                  valueMap.put("02", "BBrand");
                  valueMap.put("03", "CBrand");

                  brandSelectItem.setSortField(MYAssaAbloyConstants.VALUE);
                  brandSelectItem.setValueMap(valueMap);
                  brandSelectItem.setValueField(MYAssaAbloyConstants.BRANDFILTER_ID);
                  brandSelectItem.setDisplayField(MYAssaAbloyConstants.VALUE);

                  //And there is a timer that changes its value every 2 minutes
                  Timer brandChangeTimer = new Timer() {

                  Collection<String> values = (Collection<String>) brandSelectItem.getAttributeAsMap("valueMap")
                  .values();
                  final Queue<String> brandQueue = new LinkedList<>();
                  brandQueue.addAll(values);

                  @Override
                  public void run() {
                  String brand = StringUtils.EMPTY;
                  if (null != brandQueue.peek()) {
                  brand = brandQueue.poll();
                  brandSelectItem.setValue(brand);
                  }
                  brandQueue.add(brand);
                  }
                  };
                  brandChangeTimer.scheduleRepeating(120000);

                  Thanks

                  Comment


                    #10
                    This code doesn’t even set allowEmptyValue to false.

                    Comment


                      #11
                      Yes, i might have removed it because it was not doing any good.


                      import com.smartgwt.client.widgets.form.fields.SelectItem;
                      import java.util.LinkedHashMap;
                      import java.util.Map;
                      import com.google.gwt.user.client.Timer;
                      import java.util.Queue;
                      import java.util.LinkedList;

                      LinkedHashMap<String, String> valueMap = new LinkedHashMap<>();
                      valueMap.put("01", "ABrand");
                      valueMap.put("02", "BBrand");
                      valueMap.put("03", "CBrand");

                      //SelectItem creation
                      private SelectItem brandSelectItem = new SelectItem("BrandsName","BrandsTitle");
                      brandSelectItem.setSortField("value");
                      brandSelectItem.setValueMap(valueMap);
                      brandSelectItem.setValueField("id");
                      brandSelectItem.setDisplayField("value");
                      brandSelectItem.setAllowEmptyValue(false);

                      //And there is a timer that changes its value every 2 minutes
                      Timer brandChangeTimer = new Timer() {

                      Collection<String> values = (Collection<String>) display.getSelectItem().getAttributeAsMap("valueMap")
                      .values();
                      final Queue<String> brandQueue = new LinkedList<>();
                      brandQueue.addAll(values);

                      @Override
                      public void run() {
                      String brand = StringUtils.EMPTY;
                      if (null != brandQueue.peek()) {
                      brand = brandQueue.poll();
                      brandSelectItem.setValue(brand);
                      }
                      brandQueue.add(brand);
                      }
                      };
                      brandChangeTimer.scheduleRepeating(120000);
                      Last edited by sidharth1917; 21 Feb 2020, 00:03.

                      Comment


                        #12
                        Hi guys, please revisit (again) the Debugging topic and the FAQ to understand how to make a minimal, ready-to-run test case. This attempt refers to files we do not have and has no imports. By ready-to-run we do mean ready to run.

                        Comment


                          #13
                          Hi,
                          Sorry for the confusion.
                          I have made certain changes in the above code as suggested.

                          Thanks

                          Comment


                            #14
                            No, nothing appears to have been changed.

                            Comment


                              #15
                              Sorry, it was my mistake.
                              Check now.

                              Comment

                              Working...
                              X