JS gurus: please help me check checkboxes with a checkbox ; )
I was feeling all crappy all weekend so I took the opportunity to make some headway on Module Builder module. For those who don't know/remember, this is like a web-based script for auto-generating module source code. You check off the hooks you want to use, and it auto-generates some skeleton code for you so you don't have to go and look up function declarations. See http://drupal.org/node/55011 for more info. Anyway! The next big thing I'd like to do is allow for the definition of "groups" of hooks. Check here for a nice, pretty mock-up that Jeff Robbins put together: http://cvs.drupal.org/viewcvs/*checkout*/drupal/contributions/sandbox/webchi... So when I check "custom node type," the script should automatically go and check off hook_node_info, hook_insert, hook_update, hook_load, etc. Could someone show me a _BASIC_ example of how to do something like this, with just static HTML checkboxes and an onclick handler on one of them? I've had a really hard time trying to narrow down search terms for an example; most of the JS checkbox examples I've found seem to be written at the "Duh. What is a checkbox?" level. :\ Thanks very much in advance, -Angie
Angie Byron wrote:
I was feeling all crappy all weekend so I took the opportunity to make some headway on Module Builder module. For those who don't know/remember, this is like a web-based script for auto-generating module source code. You check off the hooks you want to use, and it auto-generates some skeleton code for you so you don't have to go and look up function declarations. See http://drupal.org/node/55011 for more info.
Anyway!
The next big thing I'd like to do is allow for the definition of "groups" of hooks. Check here for a nice, pretty mock-up that Jeff Robbins put together: http://cvs.drupal.org/viewcvs/*checkout*/drupal/contributions/sandbox/webchi... module_builder/modulemaker.graffle.pdf
So when I check "custom node type," the script should automatically go and check off hook_node_info, hook_insert, hook_update, hook_load, etc.
Could someone show me a _BASIC_ example of how to do something like this, with just static HTML checkboxes and an onclick handler on one of them? I've had a really hard time trying to narrow down search terms for an example; most of the JS checkbox examples I've found seem to be written at the "Duh. What is a checkbox?" level. :\
Here might be a useful example: http://www.mattkruse.com/javascript/checkboxgroup/index.html Here are my search results: http://www.google.com/search?q=javascript%20checkbox%20groups%20checked&sour... =mozilla2&ie=utf-8&oe=utf-8 Good luck, -- Bertrand Mansion http://www.mamasam.com - creative internet solutions http://golgote.freeflux.net - blog
On 27/03/06, Angie Byron <drupal-devel@webchick.net> wrote:
So when I check "custom node type," the script should automatically go and check off hook_node_info, hook_insert, hook_update, hook_load, etc.
Could someone show me a _BASIC_ example of how to do something like this, with just static HTML checkboxes and an onclick handler on one of them? I've had a really hard time trying to narrow down search terms for an example; most of the JS checkbox examples I've found seem to be written at the "Duh. What is a checkbox?" level. :\
I've put together some code (attached) that works. Let me know if you need any more help with it :o) -- David Carrington
David Carrington wrote:
I've put together some code (attached) that works. Let me know if you need any more help with it :o)
Thank you so much, that's perfect!! :D And thanks also to Bertrand for the reference. I'll be sure and have a look there if I get further stuck. -Angie
You'll need to figure out how to deal with unchecking though... if both module type A and module type B require hook C, then what happens if I check A, check B, then uncheck A? You can solve this in a really really dirty way ;). Javascript allows you to extend objects arbitrarily. So you can just add a checked count to the checkbox elements which is incremented every time the checkbox is programmatically checked, and decremented if it is programmatically unchecked. You only actually uncheck it if the counter reaches 0. See attached file. Steven
Steven Wittens wrote:
You'll need to figure out how to deal with unchecking though... if both module type A and module type B require hook C, then what happens if I check A, check B, then uncheck A?
...
See attached file.
Wow, Steven! Thank you so much! I hadn't considered the possibility of overlapping hooks, and building support for this in will make much better. I'll try and have a play with this code soon. :) -Angie
participants (4)
-
Angie Byron -
Bertrand Mansion -
David Carrington -
Steven Wittens