Closed (fixed)
Project:
Content Construction Kit (CCK)
Version:
5.x-1.2
Component:
General
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
29 Jul 2007 at 15:09 UTC
Updated:
2 Feb 2008 at 03:19 UTC
I have a CCK form where the user selects whether they are "certified." If they are, then I want the date and state of their certification. If not, I want those fields to not show.
Comments
Comment #1
nancydruI guess not?
Comment #2
mooffie commented[ I'm combining http://drupal.org/node/167413 here. ]
First, there's the cosmetic issue: hiding/showing some field(s) if/when some other field contains a certain value.
This can be done via jQuery: We can attach an "on change", or an "on click", event handler to the select box, or to a checkbox, and in this handler to toggle the visibility of the date field.
Here's the basic code:
I assumed we're using a checkbox (It's much easier. Besides, I had the code ready from some forum thread. You can change the code to suit your selectbox.)
OK, cosmetics aside. Now we're doing "data integrity".
First we do validation. We need to implement hook_nodeapi(). A possible solution:
Note that my 'field_cert_status' doesn't hold 'C'/'NC' but 0/1.
If we want to clear the date when 'field_cert_status == 0', then:
I'll try to put this code on my site later today.
Comment #3
mooffie commentedOK, you can see the form in action here:
http://blue.live4all.co.il/~mooffie/cms/node/add/tst
(Anonymous users have full permissions here. No need to register.)
You can download the code here:
http://blue.live4all.co.il/~mooffie/cms/sites/all/modules/support-public...
(I should have used a read date field, not a 'text' one. But I don't like the current Date API. I'm awaiting the new one.)
Comment #4
nancydru