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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:07:01+00:00 2026-05-28T01:07:01+00:00

I am using jquery-ui’s autocomplete on two input fields of an HTML form in

  • 0

I am using jquery-ui’s autocomplete on two input fields of an HTML form in a Sinatra app. They work on my local machine but not on Heroku. Jquery-ui’s datepicker works on this same page, so I know the jquery and jquery-ui javascript files are being loaded correctly. Also, I can see that the variable that I am using as the source for the autocomplete is actually getting populated from the database. There are no console errors as well.

Here’s the HTML:

<form action="/add-event" method="post">
     Date: <input id="datepicker" class="required" type="text" maxlength="50" name="date" /><br />
     Headliner: <input id="headliner" class="required" type="text" maxlength="50" name="headliner" /><br />
     Venue: <input id="venue" class="required" type="text" maxlength="50" name="venue_name" /><br />
</form>

There are some other fields in the form, but they don’t play a part in any of this.

Here’s the Jquery:

<script type="text/javascript">

    var artist_names = [<%= @artist_names %>];
    var venue_names = [<%= @venue_names %>];

    $(document).ready(function() {

        //Set button disabled
        $("input[type=submit]").attr("disabled", "disabled");

        var submitForm = function(date, headliner, venue) {

            //If form is validated enable form

            if ((date != "") && ($.inArray(headliner, artist_names) != -1) && ($.inArray(venue, venue_names) != -1)) 
                {
                    $("input:submit#event").removeAttr("disabled");
                }
                else
                {
                    $("input:submit#event").attr("disabled", true);
                }

            $('#typing').html(date+headliner + venue);
        }

        $("#datepicker").datepicker({
            onSelect: function(dateText, inst) { submitForm(this.value, $('#headliner').val(), $('#venue').val()) }
        });

        $("#headliner").autocomplete({
            source: artist_names,
            select: function(event, ui) { 
                submitForm($('#datepicker').val(), ui.item.value, $('#venue').val()); 
                $('#add-artist').empty();
                }
        });

        $("#venue").autocomplete({
            source: venue_names,
            select: function(event, ui) { 
                submitForm($('#datepicker').val(), $('#headliner').val(), ui.item.value); 
                $('#add-venue').empty(); 
                }
        });

        //Append a change event listener to you inputs
        $('#headliner').keyup(function() {
            var val = $('#headliner').val();
            if ($.inArray(val, artist_names) == -1) 
            {   
                if (val=="") 
                {
                    $('#add-artist').empty();
                }
                else 
                {
                    $('#add-artist').html("<strong>" + val + "</strong> isn't in our database. you must first add a profile for them to add this event!<br /><form action='/add-artist-event' method='post'><br />Artist Name: <input type='text' maxlength='50' name='artist_name' value='" + val +"' /><br /> Website: <input type='text' maxlength='50' name='artist_website' /><br /> Facebook: <input type='text' maxlength='50' name='artist_facebook' /><br />Twitter: <input type='text' maxlength='50' name='artist_twitter' /><br />Soundcloud: <input type='text' maxlength='50' name='artist_soundcloud' /><br />Bandcamp: <input type='text' maxlength='50' name='artist_bandcamp' /><br /><button type='button' id='add-artist-button' onclick='addNewArtist();'>Add New Artist!</button></form><br /><br />" );
                }
                $("input:submit#event").attr("disabled", true);
            }
            else
            {
                $('#add-artist').empty();
                submitForm($('#datepicker').val(), $('#headliner').val(), $('#venue').val()); 
            }

        });

        $('#venue').keyup(function() {
            var val = $('#venue').val();
            if ($.inArray(val, venue_names) == -1) 
            {   
                if (val=="") 
                {
                    $('#add-venue').empty();
                }
                else 
                {
                    $('#add-venue').html("<strong>" + val + "</strong>" + " is not in our database. you must first add a profile for this venue to add this event!<br /><form action='/add-venue-event' method='post'><br />Venue Name: <input type='text' maxlength='50' name='venue_name' value='" + val +"'/><br />Address: <input type='text' maxlength='50' name='venue_address' /><br />City: <input type='text' maxlength='50' name='venue_city' /><br />State: <input type='text' maxlength='50' name='venue_state' /><br />Zip: <input type='text' maxlength='50' name='venue_zip' /><br />Phone: <input type='text' maxlength='50' name='venue_phone' /><br /> Website: <input type='text' maxlength='50' name='venue_website' /><br /> Facebook: <input type='text' maxlength='50' name='venue_facebook' /><br />Twitter: <input type='text' maxlength='50' name='venue_twitter' /><br /><button type='button' id='add-venue-button' onclick='addNewVenue();'>Add New Venue!</button> </form><br /><br />");
                }
                $("input:submit#event").attr("disabled", true);
            }
            else
            {
                $('#add-venue').empty();
                submitForm($('#datepicker').val(), $('#headliner').val(), $('#venue').val()); 
            }

        });


    });

    var addNewArtist = function() { 
            $.post('/add-event/new-artist', {

                artist_name: $(':input[name="artist_name"]').val(),
                website: $(':input[name="artist_website"]').val(),
                facebook: $(':input[name="artist_facebook"]').val(),
                twitter: $(':input[name="artist_twitter"]').val(),
                soundcloud: $(':input[name="artist_soundcloud"]').val(),
                bandcamp: $(':input[name="artist_bandcamp"]').val()

            },

            function(output) {

                artist_names = output.split(',');

                $('#add-artist').html(output);
                $('#headliner').autocomplete("option", { source: artist_names });
            });
        };

    var addNewVenue = function() { 
            $.post('/add-event/new-venue', {

                venue_name: $(':input[name="venue_name"]').val(),
                street_address: $(':input[name="venue_address"]').val(),
                city: $(':input[name="venue_city"]').val(),
                state: $(':input[name="venue_state"]').val(),
                zip: $(':input[name="venue_zip"]').val(),
                phone: $(':input[name="venue_phone"]').val(),
                email: $(':input[name="venue_email"]').val(),
                website: $(':input[name="venue_website"]').val(),
                facebook: $(':input[name="venue_facebook"]').val(),
                twitter: $(':input[name="venue_twitter"]').val()

            },

            function(output) { 

                venue_names = output.split(',');

                $('#add-venue').html(output);
                $('#venue').autocomplete("option", { source: venue_names });
            });
    };
</script>

I was hoping to avoid including all the javascript in the question, but I think it’s best that I do. The only other piece is that when I “view source” in chrome I see the two variables are indeed getting populated with data:

var artist_names = [["'Bubonic Bear', "]];
var venue_names = [["'Electric Factory', "]];

UPDATE

If I hardcode a list for the “headliner” field’s autocomplete function, the autocomplete works.

$("#headliner").autocomplete({
            //source: artist_names,
            source: ["band1", "band2", "band3"],
            select: function(event, ui) { 
                submitForm($('#datepicker').val(), ui.item.value, $('#venue').val()); 
                $('#add-artist').empty();
                }
        });

I’m still not sure of the solution, it seems odd that a variable would be accessible in a local instance of the app and not on heroku. Anyway, I will add more if I figure out more.

  • 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-28T01:07:02+00:00Added an answer on May 28, 2026 at 1:07 am

    I don’t see how that would work anywhere. Your data sources:

    var artist_names = [<%= @artist_names %>];
    var venue_names  = [<%= @venue_names %>];
    

    come out as:

    var artist_names = [["'Bubonic Bear', "]];
    var venue_names  = [["'Electric Factory', "]];
    

    and that’s not the right format for the jQuery-UI Autocomplete widget. The source option should be a simple array of strings when you’re using an inlined source.

    You should be inlining your arrays in JSON format:

    var artist_names = <%= @artist_names.to_json %>;
    var venue_names  = <%= @venue_names.to_json  %>;
    

    and that should produce things like this:

    var artist_names = ["Bubonic Bear"];
    var venue_names  = ["Electric Factory"];
    

    and the autocomplete widget will be happy with that.

    You can play with this demo to see the difference:

    http://jsfiddle.net/ambiguous/Brb9p/

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

Sidebar

Related Questions

Using jQuery, what's the best way to find the next form element on the
Using jQuery 1.6.2 HTML that I'm operating on <select id=langId> <option value=0>Argentina - Spanish</option>
Using jQuery how would I find/extract the Spartan string if the outputted HTML page
Using jQuery Autocomplete, according to the docs you have to do the following to
Using jQuery Ajax to fetch data from local server: it works well with IE8
Using jquery, I currently append html to a div on a click event. The
Using jQuery 1.4 to do this. Adding a form to the body tag, nothing
Using jQuery autocomplete.. Want to replace hello in script below with javascript to identify
using jquery I have a autocomplete text box like the combobox example on the
Using jquery, how can I find the first div that contains an input with

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.