1

I am trying to create dynamic listbox values but getting this error in console: Uncaught TypeError: Cannot assign to read only property 'active' of [

Here's my code( pasting only the code for listbox ):

 body: [
                {
                    type: 'listbox',
                    name: 'type',
                    label: 'Panel Type',
                    value: type,
                    'values': get_author_list(),
                    tooltip: 'Select the type of panel you want'
                },
        ]
.....

And I am calling this function to get dynamic list...

  function get_author_list() {
    var d = "[{text: 'Default', value: 'default'}]";

    return d;
}

I am guessing that the values in listbox only takes static var and not dynamic. But I need to insert dynamic values in this list. Please can anyone help me find a workaround. Is there any possibility to insert via ajax?

Thanks, in advance!!

1

So the problem with the values helper was that it will only take array of objects and i was passing a string...I have corrected the code by passing an array of objects..Below is the corrected code..

body: [
        {
            type: 'listbox',
            name: 'type',
            label: 'Panel Type',
            value: type,
            'values': get_author_list(),
            tooltip: 'Select the type of panel you want'
        },
]
.....

function get_authors_list() {
    var result = [];
    var d = {};
    d['text'] = 'Default';
    d['value'] = 'default';
    result.push(d);
    return result;
}
0

If you make a reference to another function in Javascript I don't think you need the () after get_author_list.

 body: [
            {
                type: 'listbox',
                name: 'type',
                label: 'Panel Type',
                value: type,
                'values': get_author_list,
                tooltip: 'Select the type of panel you want'
            },
    ]

Also, I don't think you need the quotes around the object.

 function get_author_list() {
    var d = [{text: 'Default', value: 'default'}];

    return d;
}
  • Uncaught TypeError: Cannot read property 'text' of undefined My console log returns d as [{text: 'Default', value: 'default'}] so i am just calling get_authors_list in values as values take [{}] as param... – Parth Kumar Jan 25 '16 at 8:39
  • Did you remove the quotes? (I've made an edit to my post). Console.log should not return d as [{text: 'Default', value: 'default'}]. It should contain something like this: "[Object]0: Objectlength: 1__proto__: Array[0]" – Jeroen Jan 25 '16 at 8:47
  • Actually I have fixed the problem myself..The d should be defined as an array of objects.. I will add the solution here – Parth Kumar Jan 25 '16 at 9:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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