Wednesday, June 25, 2014

LocomotiveCMS Multiple Select/Checkbox Many to Many

OK so I fumbled around with this for quite a while in LocomotiveCMS.  To get a public submission form to work with a set of checkboxes (and presumably with a multiple select) use a form element like this:


%input.resource-selection{type: :checkbox, value: '{{ resource._slug }}', name: 'content[interests][]', id: "{{ resource._slug }}" }><{{ resource.name }}

(That is inside of a liquid iterating loop, with a resource being a single entry in resources) The relationship on the model for public submissions is linked to the model that contains a list of options, via many-to-many so if you have a resources (in our case, requestable resources)

- messages:
    label: Messages
    type: many_to_many
    required: false
    unique: false
    localized: false
    class_name: messages
    ui_enabled: true
asd
and on the other side (messages, the field was called interests, as in "what I'm interested in")


- interests:
    label: Interests
    type: many_to_many
    hint: A description of the field for the editors
    required: false
    unique: false
    localized: false
    class_name: requestable_resources
    ui_enabled: true

Hope this helps someone.  Drop a note if you want me to try clarify something.

~Nic

No comments: