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... Commented 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. Commented 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. Commented Feb 13, 2013 at 17:17
  • 1
    I've fixed my answer, now it should work :) Commented Feb 13, 2013 at 17:18
  • 1
    Now I fixed the incorrect spelling too. Now it will work for sure :) Commented 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

Sign up to request clarification or add additional context in comments.

6 Comments

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!
Give me few minutes to post you jsfiddle example.
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
Uncaught TypeError: Property 'source' of [object Object] is not a function. It happens at line 6952 of jquery-ui-1.10.0.js
Give it a function source: function() { return ['list']; }. If it works it's quick and dirty but anyway.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.