Combine select and input

Combine select and input

danielrm79danielrm79 Posts: 6Questions: 3Answers: 0
edited February 2017 in Free community support

Hi, is it posible to combine two different field types in DataTables Editor?
I mean, if I want to allow users to pick one option from a select, or allow them to type new content, if this content is not in the list.
With the code:

label: "Usuario:",
name: "Usuario",
type: "select",
ipOpts: getUsuarios()

the users can only select one item of the list, but they cannot type a new user.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,028Questions: 88Answers: 422
    Answer ✓

    You could use the Editor plugin selectize for this.
    https://editor.datatables.net/plug-ins/field-type/editor.selectize
    If you look at this page: https://github.com/selectize/selectize.js/blob/master/docs/usage.md
    you'll find the setting "create". This allows the user to enter new content.
    I like selectize because you can also limit the number of rows read. When you have a couple of thousand of options read from a database.
    Here is an example from my own coding where I explicitly exlude "create".

    fields: [ {
            label: "Department Name:",
            name:  "govdept_has_user.govDept_id",
            type: "selectize", 
            opts: {
                create: false,
                maxItems: 1,
                maxOptions: 15,
                openOnFocus: false,
                allowEmptyOption: false,
                placeholder: "Select Department"
            }
        }, {
            label: "Role:",
            name:  "govdept_has_user.role",
            type:  "selectize",
            options: 
            [
                { label: "Principal", value: "Principal" },
                { label: "Administrator", value: "Administrator" },
                { label: "Editor", value: "Editor" },
                { label: "Approver", value: "Approver" },
                { label: "Reader", value: "Reader" }
            ],
            opts: {
                create: false,
                maxItems: 1,
                allowEmptyOption: false,
                placeholder: "Select Role for this Department"
            }
        }
    ]        
    
  • danielrm79danielrm79 Posts: 6Questions: 3Answers: 0

    Thank you very much, It worked for me.

This discussion has been closed.