Module has conditional Checkboxes, need to remove value I am building a module that will have a bunch of checkboxes to enable the addition of metatags like HandheldFriendly, MobileOptimized, etc.

I want to have the first checkbox only displayed. Upon checking that item, other options should appear. (if itemA == checked, then show itemB) I actually have that working. The problem is that if you check itemA and then check itemB and save, but then uncheck itemA, when you return to the configuration page itemB will still have a value.

Here is a simple timeline showing the issue

Snapshot #1:
itemA: unchecked
itemB: unchecked (invisible)

Snapshot #2:
itemA: checked
itemB: unchecked (visible)

Snapshot #3:
itemA: checked
itemB: checked (visible)

Snapshot #4:
itemA: unchecked
itemB: checked (invisible) // PROBLEM

Between each snapshot, the form was saved. How can I automatically hide AND uncheck the value for itemB when clicking itemA so that when I re-enable itemA, itemB is still unchecked?

If I need to  provide further clarification, I can.

module code for poetic_toolkit.admin.inc file
Add a secondary submit handler to run before the main one:

array_unshift($form['#submit'], 'poetic_toolkit_admin_submit');


Then in that:

function poetic_toolkit_admin_submit($form, &amp;$form_state) {

    // check if field A is checked
    if(!$form_state['values']['poetic_toolkit_mobile_viewport_setting']) {
        // if it is not then set field B value to 0
        $form_state['values']['poetic_toolkit_enable_webapp_setting'] = 0;
    }

}


Then after this the main submit handler will fire and save our updated values.

This will only update the values once the form is saved.

Additionally, you don't want the unchecked condition on the depending item poetic_toolkit_enable_webapp_setting, because then it becomes checked whenever the dependent field poetic_toolkit_mobile_viewport_setting is checked (double negative). You also want to make sure you have the #default_value on the second item set, so that the user see's what is currently set (which will always be unchecked when the first is unchecked but could still be unchecked if the first is checked).

If you want B to become unchecked as soon as A is unchecked then you will need a jQuery solution.