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

Re: Another Potential AutoComplete Bug?

Expand Messages
  • grim_coder
    Fixed! Trick is to use forceselection = true, which sets the autocomplete field to a blank if a non-existing entry is selected, and then use onSubmit = return
    Message 1 of 5 , Oct 31, 2007
    • 0 Attachment
      Fixed!

      Trick is to use forceselection = true, which sets the autocomplete
      field to a blank if a non-existing entry is selected, and then use
      onSubmit = "return validate_form(this.ac_input.value)" which calls
      function validate_form(arg) {
      if (!arg) {
      alert('Please enter an existing user');
      return false;
      }
      else return true;
      };


      --- In ydn-javascript@yahoogroups.com, "grim_coder"
      <dariusjokilehto@...> wrote:
      >
      > Probably should mentino that I'm using a JSON datasource...
      >
      > --- In ydn-javascript@yahoogroups.com, "grim_coder"
      > <dariusjokilehto@> wrote:
      > >
      > > Hello.
      > > reviving this old thread as I'm having a similar issue.
      > >
      > > I'm not very experienced with javascript or yui - I want autocomplete
      > > to raise an alert only when the user submits the form -
      > > unmatchedItemSelectEvent does not behave this way, and can end up in
      > > an loop if the item's unmatched and the user changes tabs - not the
      > > desired behaviour!
      > >
      > > I tried your solution Kevin, but that raises an alert a few seconds
      > > after the data returned by the datasource is empty... which is
      > > annoying for the user if he just made a typo.
      > >
      > > I'm thinking I need to use an onsubmit in the form field, though I'm
      > > probably not doing it right, as I'm trying to call event listeners
      > > (the one you mentioned and unmatchedItemSelectEvent), and I've also
      > > attempted to call a method that checks if the JSON list I return is of
      > > 0 length:
      > >
      > > <form action="/Admin/UserAdmin/Profile"
      > > method="GET"
      > > name="operator_combobox"
      > > onsubmit="if ( ac.getListItemData.length == 0 ) {
      > > alert('User does not exist');
      > > return false;
      > > }">
      > >
      > > Also another issue I noticed was that if an item is selected, the form
      > > is submitted and the item details are viewed in the successive page,
      > > when you go back no the browser and then select a non-existent item,
      > > the same item's details are displayed! Tried the datasource.flushCache
      > > method, which I thought would get rid of this issue, but it didn't
      > > work... Though this would be solved in practice if the first issue
      > > could be fixed!
      > >
      > > Can anyone find a cure for this?
      > >
      > > Cheers!
      > >
      > > --- In ydn-javascript@yahoogroups.com, "daskevin" <daskevin@> wrote:
      > > >
      > > > Matt,
      > > >
      > > > I'm not sure if this what you are trying to do, but if you are
      trying
      > > > to check for "no results" found in your AutoComplete control,
      you may
      > > > be able to accomplish this with the dataReturnEvent?
      > > >
      > > > var dretEvent = function(type, args) {
      > > > var data=args[2];
      > > > if(data.length == 0) alert("Sorry. No items found with that query");
      > > > }
      > > > myAutoComplete.dataReturnEvent.subscribe(dretEvent);
      > > >
      > > > Or something like that. I too noticed that the
      > > > unmatchedItemSelectEvent fired when you lose focus on a text field.
      > > > And that seemed annoying to me.
      > > >
      > > > Cheers,
      > > > Kevin
      > > >
      > > >
      > > >
      > > > --- In ydn-javascript@yahoogroups.com, "Matt Warden" <mwarden@>
      wrote:
      > > > >
      > > > > I've come across another issue and I'm not sure if it is a bug.
      > > > >
      > > > > When the autocomplete control loses focus, the
      ._onTextboxBlur(...)
      > > > > method is fired. Part of this method includes:
      > > > >
      > > > > console.log(oSelf._bItemSelected);
      > > > > if(!oSelf._bItemSelected) {
      > > > > if(!oSelf._bContainerOpen || (oSelf._bContainerOpen &&
      > > > > !oSelf._textMatchesOption())) {
      > > > > if(oSelf.forceSelection) {
      > > > > oSelf._clearSelection();
      > > > > }
      > > > > else {
      > > > > oSelf.unmatchedItemSelectEvent.fire(oSelf,
      > oSelf._sCurQuery);
      > > > > }
      > > > > }
      > > > > }
      > > > >
      > > > > As you can see, the selection is cleared if _bItemSelected is
      false.
      > > > > _bItemSelected is set to false initially and by _populateList().
      > It is
      > > > > set to true by _selectItem().
      > > > >
      > > > > The problem is: if you call sendQuery() after a selection, then
      > > > > _populateList() gets called as the last operation in _sendQuery().
      > > > > This sets _bItemSelected to false blindly, and when the control
      > loses
      > > > > focus, the selection is cleared.
      > > > >
      > > > > This is bad!
      > > > >
      > > > > Again, I am not familiar with all the autocomplete use cases, so I
      > > > > cannot comment on a solution. But, surely, it would involve not
      > > > > blindly setting _bItemSelected in _populateList, no?
      > > > >
      > > > > So, again, can someone suggest a patch so I can complete my
      proof of
      > > > > concept? Just commenting out the line seems to work fine for
      me, but
      > > > > obviously that cant be the best solution, as the line is there
      for a
      > > > > reason.
      > > > >
      > > > > --
      > > > > Matt Warden
      > > > > Cleveland, OH, USA
      > > > > http://mattwarden.com
      > > > >
      > > > >
      > > > > This email proudly and graciously contributes to entropy.
      > > > >
      > > >
      > >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.