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 4026386
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:57:50+00:00 2026-05-20T10:57:50+00:00

I have a railsCombobox() plugin that I have implemented…it actually connects to an input

  • 0

I have a railsCombobox() plugin that I have implemented…it actually connects to an input HTML tag like the following:

$('input[id=box1]').railsCombobox();

My question:

I have many inputs with ids ranging from box1 to box5 that I want to append this plugin to, what would be the easiest and most efficient way to do so. Should I use a loop? or is there a special piece of code that can take care of that easily?

Many thanks.

Edit:
This is my javascript plugin:

$(document).ready(function(){
    jQuery('input[data-ddcombobox]').railsCombobox();
});

(function( jQuery ){
    var self = null;
    $.fn.railsCombobox =  function(){
        if(!this.railsAutoCompleter){
            this.railsAutoCompleter = new jQuery.railsCombobox(this);
        }
    //  this.init(this)
    }/*function() {
        return this.live('focus', function(){
            if(!this.railsAutoCompleter){
                this.railsAutoCompleter = new jQuery.railsCombobox(this);
            }
        });
    };*/
    jQuery.railsCombobox = function(e){
        _e = e;
        this.init(_e);
    };
    jQuery.railsCombobox.fn = jQuery.railsCombobox.prototype = {
        railsCombobox: '0.0.1'
    };  
    jQuery.railsCombobox.fn.extend = jQuery.railsCombobox.extend = jQuery.extend;
    jQuery.railsCombobox.fn.extend({
        init: function(e){
            e.delimiter = $(e).attr('data-delimiter') || null;
            function split( val ){
                return val.split( e.delimiter );
            }
            function extractLast( term ) {
                return split( term ).pop().replace(/^\s+/,"");
            }
            $(e).autocomplete({
                source: function( request, response){
                    $.getJSON( $(e).attr('data-ddcombobox'), {
                        term: extractLast(request.term)
                        }, response );
                    },
                search: function(){
                    // cusom minLength
                    var term = this.value;
                },
                focus: function(){
                    // prevent value inserted on focus
                    return false;
                },
                select: function( event, ui ){
                    var terms = split(this.value);
                    // remove the current input
                    terms.pop();
                    // add the selected item
                    terms.push(ui.item.value);
                    // add placeholder to get the comma and space at the end
                    if(e.delimiter != null){
                        term.push("");
                        this.value = terms.join(e.delimiter);
                    }else{
                        this.value = terms.join("");
                        if($(this).attr('id_element')){
                            $($(this).attr('id_element')).val(ui.item.id);
                        }
                    };
                    return false;
                }
            });
            ////////////
            this.button = $( "<button type='button'>&nbsp;</button>" )
                .attr( "tabIndex", -1 )
                .attr( "title", "Show All Items" )
                .insertAfter(e)
                .button({
                    icons: {
                        primary: "ui-icon-triangle-1-s"
                    },
                    text: false
                })
                .click(function() {
                    // close if already visibl
                    if($(e).autocomplete("widget").is(":visible")){
                        $(e).autocomplete("close");
                    }else{ 
                        if($(e).val()==""){
                            $(e).autocomplete('search', " ");
                        }else{
                            $(e).autocomplete('search', $(e).val());
                        }
                    }
                });
            ////////////
        }
    });
})( jQuery );
  • 1 1 Answer
  • 1 View
  • 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-20T10:57:51+00:00Added an answer on May 20, 2026 at 10:57 am

    You should use the # selector for ids. The best approach though is to assign your inputs the same class like autocomplete

    <input id="box1" class="autocomplete" type="text" />
    

    You can then just do

    $('.autocomplete').railsCombobox();
    

    UPDATE

    Your problem with the plugin is caused by your click handler

    .click(function() {
        // close if already visibl
        if($(e).autocomplete("widget").is(":visible")){
            $(e).autocomplete("close");
        }else{ 
            if($(e).val()==""){
                $(e).autocomplete('search', " ");
            }else{
                $(e).autocomplete('search', $(e).val());
            }
        }
    });
    

    You’re working with e which is all of the objects you passed in. In this case all of the input fields. I would open up another question regarding how to fix your plugin.

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

Sidebar

Related Questions

Have data that has this kind of structure: $input = [ { animal: 'cat',
Have a SomeLib.pro file that contains: CONFIG += debug TEMPLATE = lib TARGET =
Have a matrix report now that has Position, Hours and Wages for a location
Have following listener for keyboard ArrowDown event(it's key code is 40 ): window.onload =
Have a rather abstract question for you all. I'm looking at getting involved in
Have a bunch of WCF REST services hosted on Azure that access a SQL
Have been following Rails Tutorial by Michael Hart rails version 3.0 on mac OS
Have added the following code to my SQL query: (Note cut down version) DECLARE
Have a look at the following code to find X^y. /* Find exponent in
Have a look at one of my websites: moskah.com The problem is that it

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.