View difference between Paste ID: vBiE8RLT and dZih2FND
SHOW: | | - or go back to the newest paste.
1-
The module 'conditional_field_js' is contained within 'sites/all/modules', and has been enabled within 'admin/modules'.  However, since the module I've created is only supposed to show an alert box upon adding/editing a form, it doesn't work.  The module uses 'drupal_add_js' which calls a js file within the same module folder, and essentially is only supposed to pop an alert box.   Below are my files all contained within the same folder 'sites/all/modules/conditional_field_js':
1+
2
conditional_field_js.info
3
======================
4
5
name = Conditional Field JS
6
description = Allows us to fix 'Conditional Fields' module with a javascript file called 'conditional_field_js.js'
7
8
core = 7.x
9
10
11
======================
12
conditional_field_js.module
13
======================
14
15
function conditional_field_js_form_alter(&$form, &$form_state, $form_id) {
16
  switch ($form_id) {
17
    case 'classified_node_form':
18
    
19
// (#1) Default behavior
20-
/* Needed for function () function conditional_field_js_after_build($form, &$form_state) {}         */
20+
21
22-
 
22+
// (#2) After image field is loaded, all conditional fields display - this corrects the problem
23
      if( $form_state['rebuild'] ) {
24
        drupal_add_js(drupal_get_path('module', 'conditional_field_js') .'/conditional_field_reload.js');
25-
    case 'my_form':
25+
      }
26
27-
      break;
27+
// (#3) When form validation fails, all conditional fields display - this corrects the problem      
28
      $form['#validate'][]='conditional_field_js_form_validate';
29
  }
30
}
31
32-
/* Loads conditional_field_js.js when form is being altered.                                       */
32+
33
34
/****************************************************************************************************/
35
/* Loads required js files.                                                                         */
36
/****************************************************************************************************/
37-
  drupal_add_js ("$path/conditional_field_js.js");
37+
38
function conditional_field_js_after_build($form, &$form_state) {
39
  $path = drupal_get_path('module', 'conditional_field_js');
40-
  
40+
  drupal_add_js ("$path/conditional_field.js");
41
42
  return $form;
43
}
44
45
46-
conditional_field_js.js
46+
47
======================
48
conditional_field.js
49
======================
50
// Load DOM
51
(function ($) {
52
53
alert('hello');
54
55
}(jQuery));