views:

45

answers:

1

AutoSuggest jQuery Plugin requires an already available Data Object in order to run. I need to use the user's selection from the first input as data in the second input.

The following snippet throws an error in firebug

availableTeachers is not defined

var labs = {lesson:
                [
                    {
                        name: "FOO LESSON",
                        professors: [
                            { lab: "FOO TEACHER [Monday 3 pm]" },
                            { lab: "FOO TEACHER [Thursday 7 pm]" }
                        ]
                    },
                    {
                        name: "FOO LESSON",
                        professors: [
                            { lab: "FOO TEACHER [Tuesday 10 am]" }
                        ]
                    }
                ]
        };

firstStep.find("form input[type=text]").autoSuggest(labs.lesson, {
    selectedItemProp: "name",
    searchObjProps: "name",
    selectionLimit: 1,
    resultClick: function(data){
        availableTeachers = data.attributes;
    },
});

secondStep.find("form input[type=text]").autoSuggest(availableTeachers.professors, {
    selectedItemProp: "lab",
    searchObjProps: "lab",
    selectionLimit: 1,
});

EDIT

More testing, i predifined availableTeachers with some dummy data and i populate it with real data after the user selects a lesson.name in the first input.

Second input keeps seeing only the dummy data

So far, it seems that autoSuggest plugin can only use static Data Objects or JSON requests.

A: 

Where is availableTeachers defined? You should have some place where the variable is created. It is not enough to only assign it a value inside the lambda function, since the scope of that variable is local, unless it's created in the global scope.

geon
It is created in the global scope because i didn't put "var" before the variable's name.
fuSi0N
Do you understand what i am trying to say?
fuSi0N