Announcement

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

    combobox with picklist keypress get record

    Hello,

    Using GWT 2.4 and Smart GWT 3.0. Most fun!

    So I want to have a drop down that has formatted items, and I can get the record(s) of the item selected in the picklist that is the dropdown. I have the button click working fine, and the navigation with the keyboard. But when the enter key is clicked I can get the "enter" key, but can't seem to get the item from the pick list that was last selected. I have tried a few things.

    here is my current code. Any ideas?

    Evan

    cbSearchOn = new ComboBoxItem();
    cbSearchOn.setDisplayField("entvalue");
    cbSearchOn.setSortField("entvalue");
    cbSearchOn.setValueField("entvalue");
    DataSource ds = DataSource.get("ravisearchon");
    cbSearchOn.setOptionDataSource(ds);

    // general settings
    cbSearchOn.setHeight(28);
    cbSearchOn.setWidth(450);
    // comboBoxItemDiseases.setAnimationTime(3);
    cbSearchOn.setCompleteOnTab(true);
    // cbItem.setShowPickerIcon(true);
    // TODO: tool tip on combo box does not format so well
    cbSearchOn.setTooltip("<nobr>Start typing to reveal matches for your search.</nobr>");
    // title to the left of combo box
    cbSearchOn.setTitle("");

    // initialize and fetch when the UI loads up
    cbSearchOn.setAutoFetchData(true);

    KeyUpHandler handler = new KeyUpHandler() {
    @Override
    public void onKeyUp(KeyUpEvent event) {
    String strKeyName = event.getKeyName();
    FormItem fi = event.getItem();
    bindCurrentSearchOn(fi.getSelectedRecord());
    if (strKeyName.equals("Enter")) {
    fireEventsSearchOnResultsPage();
    }
    }
    };
    cbSearchOn.addKeyUpHandler(handler);

    ListGridField entvalue = new ListGridField("entvalue");
    entvalue.setCellFormatter(new CellFormatter() {
    @Override
    public String format(Object value, ListGridRecord record, int rowNum, int colNum) {
    return record.getAttribute("entvalue") + getFieldType(record.getAttributeAsInt("entfieldskey")) ;
    }
    });

    // The full record type is only "defined" when they select the item in the pick list
    // It does not exist in the "box", only the value does at that point
    CellClickHandler cellclickhandler = new CellClickHandler() {
    @Override
    public void onCellClick(CellClickEvent event) {
    bindCurrentSearchOn(event.getRecord());
    }
    };

    ListGrid pickListProperties = new ListGrid();
    pickListProperties.addCellClickHandler(cellclickhandler);

    KeyPressHandler keypresshandler = new KeyPressHandler() {
    @Override
    public void onKeyPress(KeyPressEvent event) {
    String strKeyName = event.getKeyName();
    if (strKeyName.equals("Enter")) {
    // bindCurrentSearchOn(fi.getSelectedRecord());
    }
    }
    };
    pickListProperties.addKeyPressHandler((com.smartgwt.client.widgets.events.KeyPressHandler) keypresshandler);

    cbSearchOn.setPickListProperties(pickListProperties);
    // cbSearchOn.setPickListBaseStyle("");
    cbSearchOn.setAnimatePickList(true);
    cbSearchOn.setPickListFields(entvalue);

    #2
    Hello,

    So the basic thing I can't seem to do is get the record in the picklist from a combobox when a user hits enter.

    I can get the "enter" event with a keypress handler on the combobox
    KeyUpHandler handler = new KeyUpHandler() {
    @Override
    public void onKeyUp(KeyUpEvent event) {
    String strKeyName = event.getKeyName();
    if (strKeyName.equals("Enter")) {
    // do something
    }
    }
    };
    combobox.addKeyUpHandler(handler);

    So the do something should get the selected record for the combobox.
    all the calls I have tried return null.
    I can get the dropdown (my picklist) with items, use the arrows to move over one. It is highlighted. I hit return, and it is not inserted into the combobox. And I can't get the highlighted item regardless of what I try.

    Thanks,
    Evan

    Comment


      #3
      Perhaps the enter key is already on the string by the key up so it does not find a match.

      Wondering what an "activated record" is, so a reference to this in the documentation.

      Evan

      Comment


        #4
        Hello,

        Still using Smart GWT 3.0 and GWT 2.4 in a firefox 7 browser.

        So I have a ListGrid assigned to a combobox so my listgrid is my dropdown.

        The following works great, for the click event and the mouse. However, I can't get the "enter" key press event. Though when a user hits enter in the listgrid the value is inserted into the combobox. So I can navigate with the arrow buttons int he list grid dropdown, and hit enter. But can't get the event occurring so I can see the "record" that is being selected in the grid before it is inserted into the combobox.

        What am I missing.

        Here is the click code which works, followed by the key press which does not fire.

        Evan

        CellClickHandler cellclickhandler = new CellClickHandler() {
        @Override
        public void onCellClick(CellClickEvent event) {
        SC.logWarn(" cell click pressed in picklist");
        bindCurrentSearchOn(event.getRecord());
        }
        };
        pickListProperties.addCellClickHandler(cellclickhandler);
        // should also turn off keyboard
        pickListProperties.setCanEdit(false);
        // should turn off keyboard
        pickListProperties.setCanFocus(false);


        and my keypress broken handler
        KeyPressHandler keypresshandler = new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
        // SC.say("keypress in picklist");
        SC.logWarn(event.getKeyName() + " pressed in picklist");
        }
        };
        pickListProperties.addKeyPressHandler(keypresshandler);

        I guess what I want is the addcell keypress handler, but I don't see that.

        Evan

        Comment


          #5
          Based on other threads I found this method. Looks promising.
          However, though I made the setting the cellClickHandler is not called when I hit enter in my picklist (ListGrid).

          Evan

          CellClickHandler cellclickhandler = new CellClickHandler() {
          @Override
          public void onCellClick(CellClickEvent event) {
          SC.logWarn(" cell click pressed in picklist");
          bindCurrentSearchOn(event.getRecord());
          }
          };
          pickListProperties.addCellClickHandler(cellclickhandler);


          pickListProperties.setGenerateClickOnEnter(true);

          Comment

          Working...
          X