Can I create a "List" field type?

Can I create a "List" field type?

Mike StoreyMike Storey Posts: 25Questions: 7Answers: 0

I have a need to use an array join of the type used in the checkbox examples, but the list of potential values is very long, so showing all the possible values in the bubble editor isn't reasonable. I would like to create a "List" control that has +/- buttons, and have the (+) button popup a dialog with a searchable dataTable of "possible" values. I know there is not a "list" field type, is there some way to accomplish this in editor?

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Hi,

    Yes it is quite possible to do this in Editor, but it would need a custom field plug-in to be created that does that, as there isn't one that exists yet.

    As we discussed by e-mail, a DataTable field plug-in might be an option that would work well for this type of case, or the select2 plug-in which does a really nice job of handling multiple values from a select list.

    Allan

  • Mike StoreyMike Storey Posts: 25Questions: 7Answers: 0
    edited January 2015

    I have a table with a many-to-one join and the editor form is working correctly with the "checkbox" field type. I'd like to do in-line editing of that list with the select2 plugin but I'm stumped. Would it be possible to get an example of how use the select2 control for inline editing of an array data set that is populated by the php library. I have this php code:

    Editor::inst( $db, 'situation', 'idsituation' )
        ->fields(
            Field::inst( 'situation.idsituation' ),
            Field::inst( 'situation.name' ),
        )
        ->join(
            Join::inst( 'tag', 'array' )
            ->join(
                array( 'idsituation', 'idsituation' ),
                array( 'idtag', 'idtag' ),
                'situationTags'
        )
        ->fields(
            Field::inst( 'idtag' )
                ->validator( 'Validate::required' )
                ->options( 'tag', 'idtag', 'name' ),
            Field::inst( 'name' )
                )
        )
        ->process( $_POST )
        ->json();
    

    and basically I'm looking to replace this javascript:

         "label": "Tags:",
         "name": "tag[].idtag",
         "type": "checkbox" 
    

    with something like this

         "label": "Tags:",
         "name": "tag[].idtag",
         "type": "select2" 
    ....and then..
         { data: "tag", render: "[, ].name", editField: "tag[].idtag" },
    
    

    but there is obviously more to this than that.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Sorry for the delay in replying to this one. The code you have above looks about right to me. I'll try to put together an example to test it locally as soon as I can (although that might be a little while due to other commitments), but if you were able to link me to the page you are using that would help to speed things up as I can debug it directly.

    Allan

  • Mike StoreyMike Storey Posts: 25Questions: 7Answers: 0
    edited February 2015

    Thanks so much Alan! The code at OpenShift does not contain this select2 code, but if you wanted to look here: http://sitgenadmin-ssgpp.rhcloud.com you can see the app with the checkbox style UI on the "Profile" editor. I really appreciate all your help!

    BTW, the "dependent" code I'm trying to get working is also in this app, on the Template accordion when you select a Template the Directives for that template are shown, and the Type Dependent code is on the Directive bubble editor.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Thanks for the link. I'll try to recreate the issue locally next week.

    Allan

This discussion has been closed.