6

I want to create a field that will ask the user for the date they started their job to when they left. If they are still currently working at the job, the user will click 'I currently work there' or something similar. The date module currently can be setup to have a 'to' and 'from' field. The tricky part is how do I save 'Current/Present' to the database. How do I go about this?

Job posting sample

6
+50

This is doable using Conditional Fields despite its rather minor limitation (http://drupal.org/node/360824). You can't trigger fields' display by a checkbox's off value. That will require you to negate the "I currently work here" checkbox to something like "Past position". You can still decide if you want it checked by default or not, and using JavaScript you can hide the "Past position" checkbox and control its value using the desired checkbox with the opposite meaning.

Saving 'Current/Present' to the database is not an issue really. You only need to check the value of the checkbox field and you can disregard the 'Current/Present' value if this is an ongoing position. To make the To date field work as expected, though, make it Required and choose an arbitrary Default value for it, which will be used even when the field is not displayed. Now would be a good bet.

Here's an image which pretty much wraps up the 5 minute content type setup.

Conditional fields setup and preview

It's obviously going to take a little more than that to make the form look and behave the exact way you want. For information on theming the resulting form, see Theming a form with conditional fields.

Also see Conditional Fields Docummentation

4

I would create 2 date fields to reproduce the "to-from" behavior of date: field_job_start and field_job_end. Then I'll create the checkbox and make it control field_job_end using Conditional Fields so that if it's checked field_job_end disappears.

Then a little theming for the node to show field_job_start to present if the checkbox is checked or field_job_start to field_job_end if not. You can also create this with a computed field.

3

I see two options...

1) You don't have to save "current/present" in your database. You can just determine if there's a "to" date on the Date field. If there isn't, they still work there. If there is a value for "to", then they don't still work there. That way you're just storing the date field instead of creating another field for "current/present". You can still use Conditional Fields for controlling whether the "to" part of the date is enabled or not.

2) Use that "I currently work here" check box (which can easily be created using a field, you probably already are) as your check for whether they currently work there. If the field is already in your form, go ahead and use it!

0

I am not fully aware of how to achieve this, but I am wondering if the CCK Select Other module might help.

0

@Jan Tomka has a great answer. Allow me to share an alternative and simpler solution that I used:

Install String Overrides to change the text "Show End Date" to "I no longer work here."

The downside of this approach is that it changes it site-wide, for all date fields. However it may be preferable to the conditional fields approach.

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.