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

how to show/hide message base on autocomplete results

Expand Messages
  • preethimaddy
    Hi.. I have a textfield in which im implementing autocomplete.the autocomplete functionality is called after the user types in the first 5 characters.Now my
    Message 1 of 2 , Oct 1, 2008
    • 0 Attachment
      Hi..
      I have a textfield in which im implementing autocomplete.the
      autocomplete functionality is called after the user types in the
      first 5 characters.Now my requirement is the user can still type in
      data even if it doesnt show up in the the div container.Say for
      example i create a textfield for cities.After the user types in the
      first 3 chars it shows me a list of cities .The user can pick one
      from that list ot type in the city if not found in the list.Now i
      need to show a message "city is found" next to the textbox if the
      user selects one from the autocomplete list else dont display message.

      I have been able to show/hide the message but the problem is say the
      user first selects the city from the list so i show the message but
      for some reason its the wrong city the user hits the backspace and
      clears the value the message is still shown how do i hide it..In the
      testfield when the user changes the value i need to hide that message
      any suggestion how to do it.. Can soem one help me in telling what
      should i be doing to achieve this.is there any event i could use.

      code:
      ----------------------------------------------------------------------
      ----------

      var myAutoComp = new YAHOO.widget.AutoComplete
      ("myInput","myContainer", myDataSource);
      myAutoComp.prehighlightClassName = "yui-ac-prehighlight";
      myAutoComp.maxResultsDisplayed = 20;
      myAutoComp.useShadow = true;
      myAutoComp.minQueryLength = 5;
      myAutoComp.allowBrowserAutocomplete = false; var
      itemSelectHandler = function(sType, aArgs) {
      var data = aArgs[2]; //This would return the list of cities};
      myAutoComp.formatResult = function(aResultItem, sQuery) {
      var sKey = aResultItem[0]; // the entire result key
      sKey = sKey.replace(/&/g,"&");
      if (sKey)
      return sKey;
      else
      return "";}; //subscribe handler to the event,
      assuming//you have an AutoComplete instance
      myAC:myAutoComp.itemSelectEvent.subscribe(itemSelectHandler);
    • Eric Miraglia
      preethimaddy, Check out this message show/hide example based on the basic AutoComplete example from our website:
      Message 2 of 2 , Oct 3, 2008
      • 0 Attachment
        preethimaddy,

        Check out this message show/hide example based on the basic AutoComplete example from our website:


        Let me know if you have further questions.

        -Eric


        On Oct 1, 2008, at 5:22 PM, preethimaddy wrote:

        Hi..
        I have a textfield in which im implementing autocomplete. the 
        autocomplete functionality is called after the user types in the 
        first 5 characters.Now my requirement is the user can still type in 
        data even if it doesnt show up in the the div container.Say for 
        example i create a textfield for cities.After the user types in the 
        first 3 chars it shows me a list of cities .The user can pick one 
        from that list ot type in the city if not found in the list.Now i 
        need to show a message "city is found" next to the textbox if the 
        user selects one from the autocomplete list else dont display message.

        I have been able to show/hide the message but the problem is say the 
        user first selects the city from the list so i show the message but 
        for some reason its the wrong city the user hits the backspace and 
        clears the value the message is still shown how do i hide it..In the 
        testfield when the user changes the value i need to hide that message 
        any suggestion how to do it.. Can soem one help me in telling what 
        should i be doing to achieve this.is there any event i could use.

        code:
        ------------ --------- --------- --------- --------- --------- -
        ----------

        var myAutoComp = new YAHOO.widget. AutoComplete
        ("myInput"," myContainer" , myDataSource) ; 
        myAutoComp.prehighl ightClassName = "yui-ac-prehighligh t";
        myAutoComp.maxResul tsDisplayed = 20;
        myAutoComp.useShado w = true; 
        myAutoComp.minQuery Length = 5; 
        myAutoComp.allowBro wserAutocomplete = false; var 
        itemSelectHandler = function(sType, aArgs) {
        var data = aArgs[2]; //This would return the list of cities}; 
        myAutoComp.formatRe sult = function(aResultIte m, sQuery) {
        var sKey = aResultItem[ 0]; // the entire result key
        sKey = sKey.replace( /&/g,"&") ; 
        if (sKey)
        return sKey;
        else
        return "";}; //subscribe handler to the event, 
        assuming//you have an AutoComplete instance 
        myAC:myAutoComp. itemSelectEvent. subscribe( itemSelectHandle r); 


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