Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5936213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:22:01+00:00 2026-05-22T15:22:01+00:00

I’m using the code found in this jsbin: http://jsbin.com/asahe5/10/edit There is a function within

  • 0

I’m using the code found in this jsbin: http://jsbin.com/asahe5/10/edit

There is a function within that class called addItem, which adds an auto-suggested item to the page. However, there is no API built in to add something by clicking on a button for example.

I have tried the following, but it doesn’t work (Uncaught TypeError: Object [object Object] has no method ‘addItem’):

var test = $("#test").jSuggest({
    source: 'http://example.com/page.php',
    minChars: 1,
    keyDelay: 200,
    selectedItemProp: 'name',
    seekVal: 'name',
    startText: 'Enter a country',
    newItem: false,
    newText: 'Please select a country from the list.',
    selectionAdded: function(elem, data){ add_country(data.value); },
    selectionRemoved: function(elem, data){ elem.fadeTo("fast", 0, function(){ elem.remove(); rem_country(data.value); }); }
});

function add_item(object, id) {
    test.addItem(object, id);
}

The most relevant part of the plugin:

(function($){

  $.fn.jSuggest = function(options) {
    var defaults = {
      source: {}, // Object or URL where jSuggest gets the suggestions from.
      uniqID: false,
      startText: 'Enter a Value', // Text to display when the jSuggest input field is empty.
      emptyText: 'No Results Found', // Text to display when their are no search results.
      preFill: {}, // Object from which you automatically add items when the page is first loaded.
      limitText: 'No More Values Are Allowed', // Text to display when the number of selections has reached it's limit.
      newItem: false, // If set to false, the user will not be able to add new items by any other way than by selecting from the suggestions list.
      newText: 'Adding New Values Is Not Allowed', // Text to display when the user tries to enter a new item by typing.
      selectedItemProp: 'value', // Value displayed on the added item
      selectProp: 'value', // Name of object property added to the hidden input.
      seekVal: 'value', // Comma separated list of object property names.
      queryParam: 'q', // The name of the param that will hold the search string value in the AJAX request.
      queryLimit: false, // Number for 'limit' param on ajax request.
      extraParams: '', // This will be added onto the end of the AJAX request URL. Make sure you add an '&' before each param.
      matchCase: false, // Make the search case sensitive when set to true.
      minChars: 1, // Minimum number of characters that must be entered before the search begins.
      keyDelay: 400, //  The delay after a keydown on the jSuggest input field and before search is started.
      resultsHighlight: true, // Option to choose whether or not to highlight the matched text in each result item.
      selectionLimit: false, // Limits the number of selections that are allowed.
      showResultList: true, // If set to false, the Results Dropdown List will never be shown at any time.
      selectionClick: function(elem){}, // Custom function that is run when a previously chosen item is clicked.
      selectionAdded: function(elem, data){}, // Custom function that is run when an item is added to the items holder.
      selectionRemoved: function(elem, data){ elem.remove(); }, // Custom function that is run when an item is removed from the items holder.
      spotFirst: true, // Option that spots the first suggestions on the results list if true.
      formatList: false, // Custom function that is run after all the data has been retrieved and before the results are put into the suggestion results list. 
      beforeRetrieve: function(string){ return string; }, // Custom function that is run before the AJAX request is made, or the local objected is searched.
      retrieveComplete: function(data){ return data; },
      resultClick: function(data){}, // Custom function that is run when a search result item is clicked.
      resultsComplete: function(){} // Custom function that is run when the suggestion results dropdown list is made visible.
    };  

    // Merge the options passed with the defaults.
    var opts = $.extend(defaults, options);     

    // Get the data type of the source.
    var dType = typeof opts.source;

.....................................

        function addItem(data, num) {

          // Add to the hidden input the seleced values property from the passed data.
          hiddenInput.val(hiddenInput.val()+data[opts.selectProp]+',');

          // If a selected item is clicked, add the selected class and call the custom selectionClick function.
          var item = $('<li class="as-selection-item" id="as-selection-'+num+'"></li>').click(function() {

            opts.selectionClick.call(this, $(this));
            itemsHolder.children().removeClass('selected');
            $(this).addClass('selected');

          });

          // If the close cross is clicked, 
          var close = $('<a class="as-close">x</a>').click(function() {

            // Remove the item from the hidden input.
            hiddenInput.val(hiddenInput.val().replace(data[opts.selectProp]+',',''));

            // Call the custom selectionRemoved function.
            opts.selectionRemoved.call(this, item, data);
            input.focus();
            return false;

          });

          // Insert the item with the selectedItemProp as text and the close cross.
          orgLI.before(item.html(data[opts.selectedItemProp]).prepend(close));

          // Call the custom selectionAdded function with the recently added item as elem and its associated data.
          opts.selectionAdded.call(this, orgLI.prev(), data);

        }

.....................................

      });

    }

  };

})(jQuery);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:22:02+00:00Added an answer on May 22, 2026 at 3:22 pm

    You can’t call that function without changing the plugin to expose the function as a visible API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.