You are here

function webform_conditional_add_js in Webform Conditional (Same Page Conditionals) 7

Same name and namespace in other branches
  1. 6 webform_conditional.module \webform_conditional_add_js()

Function run #after_build on webform. This ensures that Javascript is added even if form is built from cache.

_state

Parameters

array $form:

Return value

array The form

1 string reference to 'webform_conditional_add_js'
webform_conditional_form_alter in ./webform_conditional.module

File

./webform_conditional.module, line 265
This module adds the ability to have hidden conditional fields on Webforms. It requires the Webform module version 3.x

Code

function webform_conditional_add_js(&$form, $form_state) {

  // If the form is being rebuilt we need to reset the previous settings,
  // otherwise array_merge_recursive() will turn string values into arrays.
  $javascript =& drupal_static('drupal_add_js', array());
  foreach ($javascript['settings']['data'] as $delta => $settings) {
    if (key($settings) == 'webform_conditional') {
      unset($javascript['settings']['data'][$delta]);
      break;
    }
  }
  drupal_add_js($form['#webform_conditional_js'], array(
    'type' => "setting",
    'scope' => JS_DEFAULT,
  ));
  drupal_add_js(drupal_get_path('module', 'webform_conditional') . '/webform_conditional.js');
  return $form;
}