Loading ...
Sorry, an error occurred while loading the content.
 

Re: [ydn-javascript] Menu does not scroll into selected MenuItem

Expand Messages
  • Daniel Dekel
    Hi Todd, The example Jenny did looks good for me. Anyway, I think it would be also good to find a solution for the menu problem I have. The problem is simple
    Message 1 of 4 , Oct 2 12:13 AM
      Hi Todd,

      The example Jenny did looks good for me. Anyway, I think it would be also good to find a solution for the menu problem I have.

      The problem is simple to understand. The Menu has many Items, it means it scrolls. I also "select" an item that is in downstairs, inside the scrollable area (not visible). I would like the menu to scroll and show the selected item without using the "focus" function. Same way "select" tag in HTML works.


      The code (Look at the "red" code) and thank you in advance! - DanielD:

      function createTimePicker(id, inputEl){
             
              // Create Menu data:
              var menuData = getMenuData();

              menu = new YAHOO.widget.Menu("timePickerMenu", {
                  maxheight: 200,
                  scrollincrement: 3,
                  lazyload: true
                  });
              menu.localInputEl = inputEl;
              menu.addItems(menuData);
              menu.render(document.body);
             
              menu.open = function(localInputEl){
                 
                  menu.localInputEl = localInputEl;
                 
                  // Get Time
                  time = getTime(menu.localInputEl);
         
                  if(!validateTime(time, menu.localInputEl)){
                      return;
                  }
                 
                  menu.cfg.setProperty("context", (typeof context!="undefined") ? [menu.localInputEl, context.from, context.to] : [menu.localInputEl, "tr", "br"]);
                 
                  menu.show();
                 
                  // Select MenuItem:
                  // Get index of menuitem to select:
                  var hoursInt = parseInt(time.hours);
                  var indexMenuItem = (hoursInt*2)-2;
                 
                  if(useMeridianTime){
                      if(hoursInt>12)
                          indexMenuItem = indexMenuItem*2;
                  }
                  if(time.minutes!="00"){
                      indexMenuItem++;
                  }
                 
                  menu.getItem(indexMenuItem).cfg.setProperty("selected", true);
      //            menu.getItem(indexMenuItem).focus();
                 
                  // On Menu select:
                  menu.subscribe("click", function(p_sType, p_aArgs){
                       var oMenuItem = p_aArgs[1];
                       if (oMenuItem) {
                           menu.localInputEl.value = oMenuItem.cfg.getProperty("text");
                       }
                  });
                 
                  // Validate when menu is hidden:
                  menu.subscribe("hide",function(){
                      if(!validateTime(getTime(menu.localInputEl))){
                          YAHOO.util.Dom.addClass(menu.localInputEl, "error");
                      } else {
                          YAHOO.util.Dom.removeClass(menu.localInputEl, "error");
                      }
                  });
                 
                  // Arrow-Down Key listener on Input:
                  // Set focus to menu in case key down is pressed from input menu:
                  var key = new YAHOO.util.KeyListener(menu.localInputEl, {keys:40}, {fn:function(){
                      menu.focus();
                  }});
                  key.enable();
              }
          }

      ----- Mensaje original ----
      De: Todd Kloots <kloots@...>
      Para: ydn-javascript@yahoogroups.com; dekeldaniel@...
      Enviado: jueves, 2 de octubre, 2008 9:44:15
      Asunto: Re: [ydn-javascript] Menu does not scroll into selected MenuItem

      Hi Daniel -

      Jenny, the author of the YUI Autocomplete widget just created a combox
      example for 2.6.0 that you might find useful:

      http://developer.yahoo.com/yui/examples/autocomplete/ac_combobox.html

      If not, can you provide a URL to the code that that is causing you
      trouble so that I can have a look?  Otherwise it is hard to help.

      - Todd

      Daniel Dekel wrote:
      > Hi, Can you please help me? Any idea regarding this issue?
      >
      > Thank you,
      >
      > DanielD.
      >
      > ----- Mensaje original ----
      > De: dekeldaniel <dekeldaniel@...>
      > Para:
      ydn-javascript@yahoogroups.com
      > Enviado: martes, 23 de septiembre, 2008 13:37:41
      > Asunto: [ydn-javascript] Menu does not scroll into selected MenuItem
      >
      > Hi,
      > I am simulating an Editable Combo box menu. it means I have a text box
      > and on a click, a menu (yui) comes up with a list of options.
      > This list has a selected item.
      >
      > The problem:
      > Since there is scroll in the menu, the menu does not scroll in to the
      > selected item.
      > I tried using the focus() for menuItem, but is no good since I still
      > need to keep the focus on the input text.
      >
      > 1. Does anyone knows a simple way to make it work?
      > 2. Does anyone knows a simple way to generate an editable combobox as
      > it is in many other UI Libraries?
      >
      > Thank you,
      >
      >
      Daniel.
      >
      >
      >


    Your message has been successfully submitted and would be delivered to recipients shortly.