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

YUI Autocomplete and preselecting with datasource object

Expand Messages
  • studmanie
    Hi, I have a datasource that was generated with a localsource off an array of objects. The objects have a name and id. When a user types and selected in the
    Message 1 of 4 , Nov 25, 2008
      Hi, I have a datasource that was generated with a localsource off an
      array of objects. The objects have a name and id.

      When a user types and selected in the autocomplete, it will
      appropriately use the name to find filter the list and then they can
      select the object.

      When a user brings the form back up again to edit information, I want
      the autocomplete widget to prepopulate with a previously selected id.
      It seems like I can only use autocomplete.sendQuery for the "name"
      attribute of the object and not id. Anyone know of a way to select the
      right object for the autocomplete widget by the objects "id" instead
      of "name" value?
    • jennykhan
      Hi studmanie, You should be able to switch the field being searched at runtime by switching the order of the schema fields: myDataSource.responseSchema.fields
      Message 2 of 4 , Nov 25, 2008
        Hi studmanie,

        You should be able to switch the field being searched at runtime by
        switching the order of the schema fields:

        myDataSource.responseSchema.fields = ["id", "name"];

        If that doesn't resolve your issue, please post a URL to a repro case
        (or post the entirety of your code) and be sure to include detailed
        info on expected vs actual behavior for further debugging.

        Regards,
        Jenny




        --- In ydn-javascript@yahoogroups.com, "studmanie" <caryho@...> wrote:
        >
        > Hi, I have a datasource that was generated with a localsource off an
        > array of objects. The objects have a name and id.
        >
        > When a user types and selected in the autocomplete, it will
        > appropriately use the name to find filter the list and then they can
        > select the object.
        >
        > When a user brings the form back up again to edit information, I want
        > the autocomplete widget to prepopulate with a previously selected id.
        > It seems like I can only use autocomplete.sendQuery for the "name"
        > attribute of the object and not id. Anyone know of a way to select
        the
        > right object for the autocomplete widget by the objects "id" instead
        > of "name" value?
        >
      • studmanie
        Wow thanks. That works really well but... It seems like the objects that I placed into the datasource are stored in arrays so when i change the response schema
        Message 3 of 4 , Nov 26, 2008
          Wow thanks. That works really well but...

          It seems like the objects that I placed into the datasource are stored
          in arrays so when i change the response schema to
          dataSource.responseSchema = {fields: ["id", "name"]};

          my

          myAutoComp.formatResult = function(oResultData, sQuery, sResultMatch){
          return oResultData[0] + " " + oResultData[1];
          };

          comes out as an backwards.

          Also, when I use sendQuery() it filters the list correctly but doesnt
          populate the autocomplete field. Is there a way to do that?

          The idea is that the name component is not unique, there can be many
          objects with the same name, but the id is unique. So I need them to be
          able to narrow down by name, then select in the list by id. BUT when I
          want to prepopulate the autocomplete, I need the selected item to be
          found by id and the name put into the field. Is this possible?


          --- In ydn-javascript@yahoogroups.com, "jennykhan" <jennyhan@...> wrote:
          >
          > Hi studmanie,
          >
          > You should be able to switch the field being searched at runtime by
          > switching the order of the schema fields:
          >
          > myDataSource.responseSchema.fields = ["id", "name"];
          >
          > If that doesn't resolve your issue, please post a URL to a repro case
          > (or post the entirety of your code) and be sure to include detailed
          > info on expected vs actual behavior for further debugging.
          >
          > Regards,
          > Jenny
          >
          >
          >
          >
          > --- In ydn-javascript@yahoogroups.com, "studmanie" <caryho@> wrote:
          > >
          > > Hi, I have a datasource that was generated with a localsource off an
          > > array of objects. The objects have a name and id.
          > >
          > > When a user types and selected in the autocomplete, it will
          > > appropriately use the name to find filter the list and then they can
          > > select the object.
          > >
          > > When a user brings the form back up again to edit information, I want
          > > the autocomplete widget to prepopulate with a previously selected id.
          > > It seems like I can only use autocomplete.sendQuery for the "name"
          > > attribute of the object and not id. Anyone know of a way to select
          > the
          > > right object for the autocomplete widget by the objects "id" instead
          > > of "name" value?
          > >
          >
        • jennykhan
          Hi Studmanie, There is a (relatively) new AutoComplete property you can set to pass data to your formatResult() method as an object literal rather than an
          Message 4 of 4 , Dec 1, 2008
            Hi Studmanie,

            There is a (relatively) new AutoComplete property you can set to
            pass data to your formatResult() method as an object literal rather
            than an array:

            myAutoComplete.resultTypeList = false;
            myAutoComp.formatResult = function(oResultData, sQuery, sResultMatch)
            {
            return oResultData.name + " " + oResultData.id;
            };


            To filter by ID but populate by name, you'll want to hook into the
            itemSelectEvent and update the DOM element yourself. Take a look at
            this example to get started, but instead of updating the hidden
            field, you can update the textbox directly:
            http://developer.yahoo.com/yui/examples/autocomplete/ac_itemselect.ht
            ml

            Hope that helps,
            Jenny



            --- In ydn-javascript@yahoogroups.com, "studmanie" <caryho@...>
            wrote:
            >
            > Wow thanks. That works really well but...
            >
            > It seems like the objects that I placed into the datasource are
            stored
            > in arrays so when i change the response schema to
            > dataSource.responseSchema = {fields: ["id", "name"]};
            >
            > my
            >
            > myAutoComp.formatResult = function(oResultData, sQuery,
            sResultMatch){
            > return oResultData[0] + " " + oResultData[1];
            > };
            >
            > comes out as an backwards.
            >
            > Also, when I use sendQuery() it filters the list correctly but
            doesnt
            > populate the autocomplete field. Is there a way to do that?
            >
            > The idea is that the name component is not unique, there can be
            many
            > objects with the same name, but the id is unique. So I need them
            to be
            > able to narrow down by name, then select in the list by id. BUT
            when I
            > want to prepopulate the autocomplete, I need the selected item to
            be
            > found by id and the name put into the field. Is this possible?
            >
            >
            > --- In ydn-javascript@yahoogroups.com, "jennykhan" <jennyhan@>
            wrote:
            > >
            > > Hi studmanie,
            > >
            > > You should be able to switch the field being searched at runtime
            by
            > > switching the order of the schema fields:
            > >
            > > myDataSource.responseSchema.fields = ["id", "name"];
            > >
            > > If that doesn't resolve your issue, please post a URL to a repro
            case
            > > (or post the entirety of your code) and be sure to include
            detailed
            > > info on expected vs actual behavior for further debugging.
            > >
            > > Regards,
            > > Jenny
            > >
            > >
            > >
            > >
            > > --- In ydn-javascript@yahoogroups.com, "studmanie" <caryho@>
            wrote:
            > > >
            > > > Hi, I have a datasource that was generated with a localsource
            off an
            > > > array of objects. The objects have a name and id.
            > > >
            > > > When a user types and selected in the autocomplete, it will
            > > > appropriately use the name to find filter the list and then
            they can
            > > > select the object.
            > > >
            > > > When a user brings the form back up again to edit information,
            I want
            > > > the autocomplete widget to prepopulate with a previously
            selected id.
            > > > It seems like I can only use autocomplete.sendQuery for
            the "name"
            > > > attribute of the object and not id. Anyone know of a way to
            select
            > > the
            > > > right object for the autocomplete widget by the objects "id"
            instead
            > > > of "name" value?
            > > >
            > >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.