1

I am using jquery-1.9.0 and jquery-ui-1.10.0

var opts = {
            source: availableTags
        };

    var optsA = Object.create(opts, 
    {
        select: {
            value: function (event, ui) {}
        }
    });

    var optsB = Object.create(opts, 
    {
        select: {
            value: function (event, ui) {}
        }
    });

    $("#tags1").autocomplete(
        optsB
    );

    $("#tags2").autocomplete(
        optsA
    );

I am trying to build up two seperate arguments lists for my autocompletes. The objects seem to be constructed correctly but the autocomplete doesnt seem to recognise my definition for the select in the inherited objects.

5
  • 1
    It looks pretty strange. If you add select method to: optsA.__proto__ it works but if you add it to the object it doesn't... Feb 13, 2013 at 17:06
  • I am thinking the Bind option you posted might be a better approach for solving this issue instead of trying to use classic OO concepts.
    – Jonathan
    Feb 13, 2013 at 17:10
  • Obviously I am only sharing a little of my code, this is actually a much bigger argument list therefore my own insistance that its modularized.
    – Jonathan
    Feb 13, 2013 at 17:17
  • 1
    I've fixed my answer, now it should work :) Feb 13, 2013 at 17:18
  • 1
    Now I fixed the incorrect spelling too. Now it will work for sure :) Feb 13, 2013 at 17:18

1 Answer 1

1

There's a missing property in the Object.create invocation.

You should add enumerable: true

var opts = {
    source: availableTags
};

var optsA = Object.create(opts, 
{
    select: {
        value: function (event, ui) {},
        enumerable: true
    }
});

var optsB = Object.create(opts, 
{
    select: {
        value: function (event, ui) {},
        enumerable: true
    }
});

$("#tags1").autocomplete(
    optsB
);

$("#tags2").autocomplete(
    optsA
);

The problem is that the for in loop in jQuery's core extend method can't find the select property because it's not marked as enumerable so that's why it's not accessible from inside the autocomplete.

JSFiddle

6
  • I cant seem to get this to work. It seems right to me but its not working, any ideas? How can I trouble shoot the issue. Many thanks for your help!
    – Jonathan
    Feb 14, 2013 at 9:56
  • 1
    Give me few minutes to post you jsfiddle example. Feb 14, 2013 at 10:00
  • I am using jquery-1.9.0 and jquery-ui-1.10.0 it doesnt seem to work for this combination, any ideas or recommendations? jsfiddle.net/EBduF/309
    – Jonathan
    Feb 14, 2013 at 15:06
  • Uncaught TypeError: Property 'source' of [object Object] is not a function. It happens at line 6952 of jquery-ui-1.10.0.js
    – Jonathan
    Feb 14, 2013 at 15:22
  • 1
    Give it a function source: function() { return ['list']; }. If it works it's quick and dirty but anyway. Feb 14, 2013 at 16:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.