0

This answer has given me most of what I need, but I'd like to hide certain settings based on the status of other settings. CP seems to have nice functionality built in for conditionally hiding/showing parameters. For example, when changing a field from Rich Text to Plain Text, several options disappear.

In this case, only if the preceding checkbox is checked do I want it to give an input field for the category field handle.

Here is my /craft/plugins/calendar37/templates/_settings.html file:

{% import "_includes/forms" as forms %}

{{ forms.checkBox({
        label: "Event Hyperlinking"|t,
        id: 'eventClickDestination',
        name: 'eventClickDestination',
        instructions: "If checked, clicking on an event goes to Category page. Otherwise, unchecked it will go an Entry page"|t,
        value: settings.eventClickDestination,
        errors: settings.getErrors('eventClickDestination')
    })
}}

{{ forms.textField({
        label: "Category Field's Handle"|t,
        id: 'categoryFieldHandle',
        name: 'categoryFieldHandle',
        instructions: ""|t,
        value: settings.categoryFieldHandle,
        errors: settings.getErrors('categoryFieldHandle')
    }) 
}}

Note, I'd like to work out similar functionality with a 3-part radio button, but haven't figured out how to do radio buttons yet.

Thank you!

2

I'm not sure how to do a 3 way toggle with radio boxes, it might involve writing your own JS... but for the checkbox toggle it's pretty straight forward :)

{{ forms.checkboxField({
    ...
    toggle : 'toggleThis'
}) }}

<div id="toggleThis" {% if settings.eventClickDestination is not defined or not settings.eventClickDestination %} class="hidden"{% endif %}>
  //.. Form input goes in here
</div>

Craft will then take care of the toggling for you when the box is checked/unchecked

  • Thank you, Alec. Where does the <div id="toggleThis" go? – kr37 May 29 '15 at 16:20
  • Wherever in your template you want the field to appear :) – Alec Ritson May 29 '15 at 16:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.