How do I remove multiple objects from avail when one is selected?

Rich Massa's Avatar

Rich Massa

22 Apr, 2011 12:46 PM

If the user selects drop down item A, (with the bug fix) the autoSuggest list removes A from being available to be selected a second time. I want to be able to remove A,B, and C when A is selected so that only D, E...etc are shown. Is there any method that can easily remove an item from the available data list if I pass it the JSON object?

Thank you for your time.

  1. 1 Posted by Rich Massa on 22 Apr, 2011 12:46 PM

    Rich Massa's Avatar

    Not resloved...please reopen discussion

  2. 2 Posted by jSuggest on 22 Apr, 2011 02:02 PM

    jSuggest's Avatar

    Yes, there is the formatList custom function, that lets you customize what is shown in your results list.

     formatList: function(data, elem){
          var new_elem = elem.html("add/change stuff here, put image here, etc.");
          return new_elem;
      }
    

    Check if your item is already selected and then remove from the "data" object or the "elem", the items you don't want to be displayed.

  3. 3 Posted by Rich Massa on 22 Apr, 2011 02:05 PM

    Rich Massa's Avatar

    Ok thanks, I'm not to javascript, would anyone happen to have an example by chance?

    I assume that I can grab the other object for the other items that I don't want to be displayed somehow, but how would I explicitly remove them? Is there a .remove() function or a .hide() flag ?

  4. 4 Posted by Rich Massa on 22 Apr, 2011 07:17 PM

    Rich Massa's Avatar

    Ok I think i got it working by creating a new array to track elements that have been added:

      var selected_group = new Array();
      var count = 0;
    

    And when clicking I check to see if the element is in the array before adding it to the array, but i still need to send the output returned from the formatList and I can't figure out what that would be? (elem returns blank selectable fields, but i want the original html and elem.html doesn't work either):

    formatList: function(data, elem){

                                                                              if (selected_group.length > 0 && data.optgroup)
                                                                              {
                                                                                  for(x=0;x < selected_group.length;x++)
                                                                                  {
                                                                                      if(data.group_label == selected_group[x])
                                                                                      {
                                                                                          return "";
                                                                                      }
                                                                                  }
                                                                              }
                                                                              return elem;
                                            },
                                            resultClick: function(data){
                                                                          if (data.attributes.optgroup) 
                                                                          {
                                                                              for(x=0;x < selected_group.length;x++)
                                                                              {
                                                                                  if(data.attributes.group_label != selected_group[x])
                                                                                  {
                                                                                      count++;
                                                                                  }
                                                                              }
    
                                                                              if (count == selected_group.length)
                                                                              {
                                                                                  selected_group.push(data.attributes.group_label);
                                                                              }
                                                                          }
                                                                       }
    

    Thanks for any help, I also need to add in the remove if use closes a selected value.

  5. 5 Posted by Rich Massa on 22 Apr, 2011 07:21 PM

    Rich Massa's Avatar

    here is a better snapshot:

    formatList: function(data, elem){

                      if (selected_group.length > 0 && data.optgroup)
                      {
                          for(x=0;x < selected_group.length;x++)
                          {
                              if(data.group_label == selected_group[x])
                              {
                                  return "";
                              }
                          }
                      }
                      return elem;
    

    }, resultClick: function(data){

                  if (data.attributes.optgroup)
                  {
                      for(x=0;x < selected_group.length;x++)
                      {
                          if(data.attributes.group_label != selected_group[x])
                          {
                              count++;
                          }
                      }
    
                      if (count == selected_group.length)
                      {
                          selected_group.push(data.attributes.group_label);
                      }
                  }
               }
    

    });

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac