Jump to content

New module InputfieldDependentCheckboxes


gebeer
 Share

Recommended Posts

Happy New Year to everyone!

For a project that I'm working on, I needed to have dependent checkboxes on page edit forms in the admin. Just like dependent selects but for checkboxes. I couln't find anything and decided to write my first Inputfield module.

I have only tried it on PW > 3.0. But it should also work on the 2.x branch. Would be great if some of you could try it out and give some feedback.

You can find the module InputfieldDependentCheckboxes at github

Here's some screenshots of the module in action and instructions on how to use it.

##An Inputfield for ProcessWire admin interface that handles the display of dependent checkboxes in page fields
Sometimes we need checkboxes to depend on other checkboxes in our page edit forms. This module adds this functionality to standard page field checkboxes for 2 or more checkbox fields.
demo-1.gif

## Installation
1. Copy all of the files for this module into /site/modules/InputfieldDependentCheckboxes/
2. In your admin, go to the Modules screen and click "Refresh". Under the 'Inputfield' section, install the 'InputfieldDependentCheckboxes' module.
3. Open Modules->Configure->InputfieldPage. Under 'Inputfield modules available for page selection' add 'DependentCheckboxes' from the select dropdown and submit

install-1.png

##Field Setup
This inputfield extends the standard checkboxes for page fields. Therefore you need to have page fields configured already that you can extend with this Inputfield type.

###Prerequisites
You need to have at least 2 fields of type page that have 'Checkboxes' defined as Input field type and live on the same template.

A real world example:

There are different types of instructors. Each instructor type can have multiple different certifications.
For this to happen, we need 2 page fields (multiple):

A) instructor_types: lists pages with template 'instructor_type'
B) certifications: lists pages with template 'certification'

The certification template needs to have the instructor_types page field to assign one or more instructor_types to a certification.

###Setup (link checkbox fields)
1. Edit your page field A and go to the 'Input' Tab. Under 'Input field type' choose 'DependentCheckboxes'. Hit save. Now under 'Choose the target checkboxes field' choose the name of your field B. Hit save again.
setup-1.png

2. In your page field b make sure to choose a template under 'Input' Tab under 'Selectable Pages'->'Template of selectable page(s)'.

setup-2.png
Your fields should be setup. If you now edit a page that contains the 2 fields, the dependent checkboxes should be working. 

EDIT: And yes, this is working for multiple dependent checkboxes, too. (I have tried it with 3 so far)

 

Some notes on how the module works behind the scenes:

- parent checkboxes (actors) that have dependent checkboxes (targets) get custom data attributes applied which contain arrays of the targets' IDs

- some Javascript is initiated on acxtors and targets to handle the display based on the id arrays in the data attributes.

EDIT: since this module's mention in ProcessWire Weekly it might get some more attention. I just wanted to point out that it is still in alpha state. I will continue development and more thorough testing while implementing it in an ongoing project within the next 3-5 months or so. I will eventually release a stable version then.
If you use the module with only 2 dependent checkbox fields, it should work smoothly. There are still some quirks when using 3 or more and I need to figure out how to best resolve them. So please be patient (or jump in with ideas ;) ).

  • Like 25
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...