Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-5166

select the same item twice in a searchbox clears the selection

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: 9.6.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      Steps to Reproduce

      <zk>
        <zscript>
        ListModel model = new ListModelArray(new String[] {
          "North America", "South America", "Europe",
          "Asia", "Africa", "Oceania", "Antarctica"
        });
       
        </zscript>
        
        <searchbox id="sb" model="${model}" placeholder="An unknown place"
                   autoclose="true">
           <template name="model">
               <html><![CDATA[
               <i class="z-icon-globe"></i> ${each}
               ]]></html>
           </template>
        </searchbox>
      </zk>
      
      

      2. select "North America" twice

      Current Result

      the "North America" is not selected

      Expected Result

      the "North America" is selected

      Debug Information

      1. in single selection mode, searchbox works like a drop-down. A dropdown doesn't de-select an item when selecting the same item again. This is a very common behavior among dropdowns on the web. The searchbox should behave in the most common way.

      Workaround

      zk.afterLoad('zkmax.inp', function() {
          var exWidget = {};
          zk.override(zkmax.inp.Searchbox.prototype, exWidget, {
              _doSelectItem: function(item, bulk) {
                  var $item = jq(item),
                  selectedClass = this.$s('selected'),
                  selected = $item.hasClass(selectedClass);
                  if (!this._multiple && selected){
                      return; //select the current selected item, keep selected, do nothing
                  }
                  exWidget._doSelectItem.apply(this, arguments);
              },
          });
      });
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            hawk hawk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated: