chosen plugin with multiselect

chosen plugin with multiselect

rkspamrkspam Posts: 4Questions: 1Answers: 0

I'm writing an app with node.js. I've also installed the chosen plugin with the datatables editor and I'm using it with the multiselect option turned on. After entering more than one options into the multiselection field and pressing the update button in the editor, the debugger breaks with following exception message:

Error: update users set username = 'rolf', department = 'asdf', roles = '2', '3' where id = '6' - ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax (shortened)

The error results from the wrong concatenation of the activated multiselect options. I've also tried out several settings for the separator.

Here's the field definition:

            {
                label: 'Roles:',
                name: 'roles',
                type: 'chosen',
                separator: '|',
                attr: {
                    multiple: 'true',
                },
                options: [
                    { label: "A", value: 1 },
                    { label: "B", value: 2 },
                    { label: "C", value: 3 },
                    { label: "D", value: 4 },
                    { label: "E", value: 5 }
                ]
            },

Any ideas?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin

    This looks wrong:

    roles = '2', '3' 
    

    If you have a pipe separator I'd expect it to be submitting 2|3 from the client-side and that should be what is written to the db (unless there is some other processing going on with the server for collections?).

    Have a look at the Ajax request in your browser's network inspector and see what it is actually sending to the server.

    Thanks,
    Allan

  • rkspamrkspam Posts: 4Questions: 1Answers: 0

    Hi Allan

    Thank you for your fast response. I am an absolute beginner in nodejs and javascript development, and appreciate any help.

    The client-side ajax request looks like

    action: edit
    data[row_6][username]: rolf
    data[row_6][department]: asdf
    data[row_6][roles][]: 2
    data[row_6][roles][]: 3
    

    According to your last post I would expect something like:

    action: edit
    data[row_6][username]: rolf
    data[row_6][department]: asdf
    data[row_6][roles]: 2|3
    

    I've also tried to put the separator attribute into the attr-group:

    {
        label: 'Roles:',
        name: 'roles',
        type: 'chosen',
        attr: {
            separator: '|',
            multiple: 'true',
        },
        options: [
            { label: "A", value: 1 },
            { label: "B", value: 2 },
            { label: "C", value: 3 },
            { label: "D", value: 4 },
            { label: "E", value: 5 }
        ]
    },
    

    with the same result. The separator attribute does not seem to be taken into account, the client sends an array instead of a string.

  • rkspamrkspam Posts: 4Questions: 1Answers: 0

    You can find a test case here:
    http://www.koch-motta.ch:8000/users

    Thanks
    Rolf

  • allanallan Posts: 61,726Questions: 1Answers: 10,109 Site admin
    Answer ✓

    Ah! I see the problem - this is using Chosen. Could you try it temporarily with the built in select option? Our plug-in for Chosen doesn't support separator at the moment.

    Allan

  • rkspamrkspam Posts: 4Questions: 1Answers: 0

    Thank you Allan!

    Indeed, the problem is solved by switching to the built in select field type, as

    {
        type: 'select', 
        label: 'Roles:',
        name: 'roles',
        multiple: true,
        separator: '|',
        options: [  
            { label: "A", value: 1 },   
            { label: "B", value: 2 },
            { label: "C", value: 3 },   
            { label: "D", value: 4 },
            { label: "E", value: 5 }
            ]
    }
    

    This works, but looks ugly, as you can see in the test case.

    In this case I'll have to wait until one of the next versions of the editor supports separators in the Chosen plugin?

    Cheers,
    Rolf

This discussion has been closed.