Fix for AHAH inside replace

  1. original:
  2. <div id="edit-scheme-wrapper" class="form-item">
  3. <label for="edit-scheme">Color set: </label>
  4. <select id="edit-scheme" class="form-select" name="scheme">
  5. </select>
  6. </div>
  7.  
  8. <?php
  9.   $form['schemedelete'] = array(
  10.     '#type' => 'submit',
  11.     '#value' => t('-'),
  12.     '#ahah' => array(
  13.         'path' => 'color/js',
  14.         'wrapper' => 'edit-scheme-wrapper',
  15.         'method' => 'replace'
  16.     ),
  17.   )?>
  18. AHAH replace does this:
  19.  
  20.  
  21. <div id="edit-scheme-wrapper" class="form-item">
  22. <div>
  23. <div id="edit-scheme-wrapper" class="form-item">
  24. <label for="edit-scheme">Color set: </label>
  25. <select id="edit-scheme" class="form-select" name="scheme">
  26. </select>
  27. </div>
  28. </div>
  29. </div>
  30.  
  31. <?php
  32.  
  33. function color_js() {
  34.   //drupal_add_js('if (Drupal.jsEnabled) { $(document).ready(function() { $("#edit-poll-more").val("'. t('Add another choice') .'"); }); }', 'inline');
  35.  
  36.  
  37.   module_load_include('inc', 'color', 'color.database');
  38.    
  39.   $theme = "skiquel";
  40.   $base = drupal_get_path('module', 'color');
  41.   $info = color_get_theme_info($theme);
  42.   // Add palette fields
  43.   $palette = color_get_palette($theme, $info);
  44.  
  45.   // See if we're using a predefined scheme
  46.   if ($scheme = color_get_scheme('theme', $theme, 'hex')) {
  47.     $current = unserialize($scheme['hex']);
  48.     $current_array = explode(',', $current);
  49.   }
  50.  
  51.   // $node = (object)$_POST;
  52.  
  53.  
  54.   $form_state = array('submitted' => FALSE);
  55.   $form_build_id = $_POST['form_build_id'];
  56.   // Add the new element to the stored form. Without adding the element to the
  57.   // form, Drupal is not aware of this new elements existence and will not
  58.   // process it. We retreive the cached form, add the element, and resave.
  59.   //$form = form_get_cache($form_build_id, $form_state);
  60.  
  61.   $info['schemes']['Custom'] = '';
  62.   $form = array(
  63.     '#post'=> $_POST,
  64.     '#programmed' => FALSE);
  65.   $form['scheme'] = array(
  66.     '#type' => 'select',
  67.     '#title' => t('Color set'),
  68.     '#options' => array_flip($info['schemes']),
  69.     '#default_value' => $current,
  70.  
  71.     '#tree' => FALSE,
  72.     '#description' => " <a href=\"#\" id=\"delscheme\">" . t('Delete') . "</a> | <a href=\"#\" id=\"addscheme\">". t('Add') . "</a>",
  73.   );
  74.  
  75.   $form = form_builder('color_js', $form, $form_state);
  76.   $output = drupal_render($form);
  77.  
  78.   // We send the updated file attachments form.
  79.   // Don't call drupal_json(). ahah.js uses an iframe and
  80.   // the header output by drupal_json() causes problems in some browsers.
  81.   print drupal_to_js(array('status' => TRUE, 'data' => $output));
  82.  
  83.  
  84. }?>