Editor and multiple select list

Editor and multiple select list

webpointzwebpointz Posts: 126Questions: 30Answers: 4
edited May 2015 in Editor

I'm trying to wrap my head around an issue.

I have a MySQL database table for "users" that has a field called "addresses". This address field either has the word "all" or it has a comma delimited list of "id's" from the address table.

I'm trying to figure out how to show this list of addresses so that when a user is added, they can select "all" or select multiple entries with their current entries highlighted?

JS File:

{
                "label": "Addresses:",
                "name": "table_addresses.id",
                "type": "select"
            }   

PHP File:

        Field::inst( 'table_users.addresses' )  
            ->options( 'table_addresses', 'id', 'id' )

and

->leftJoin( 'table_addresses', 'table_addresses.id', '=', 'table_users.addresses' )

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I think you'll need a custom field type for this - have it very similar to the checkbox input type, but with the addition of a radio button for the all option. The value would then be based on that.

    Alternatively, you could use the checkbox type and have an all option in the list. Then, on submit (preSubmit) or in a server-side set formatter, check if all was submitted, and reduce the value to just that. You could also add event handlers to the checkboxes to automatically uncheck all if individual options are selected, and likewise uncheck the individual options if all is selected.

    I suspect the work involved will be fairly similar for these two approaches.

    Allan

  • webpointzwebpointz Posts: 126Questions: 30Answers: 4
    edited May 2015

    Problem is that a user can choose from a list of addresses in the hundreds.

    The user has a field called "addresses" which is a varChar field with a comma delimited listing of address "ids".

    What I want to do is bring up a MULTIPLE select list that has the users current selections highlighted and they can select more or less entries.

    Is it possible to cick into a field in the editor update window that would launch another window that would contain the list of addresses and upon closing could update the datatable editor window?

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    Answer ✓

    I think the same applies with a multiple select or something more advanced like select2 or selectize.

    Is it possible to cick into a field in the editor update window that would launch another window that would contain the list of addresses and upon closing could update the datatable editor window?

    Yes, but that isn't a feature that is built into Editor. You would need your custom plug-in to open the new layer / window with the options available and then use the API to set the values selected.

    Allan

  • webpointzwebpointz Posts: 126Questions: 30Answers: 4

    Thanks

This discussion has been closed.