Browse Source

Fixed weird bug on features where relationship form ajax was broken and relationships didn't save

Lacey Sanderson 10 years ago
parent
commit
f4527d659e

+ 7 - 6
tripal_core/api/tripal_core.chado_nodes.relationships.api.inc

@@ -189,8 +189,6 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
 
   }
 
-  $form_state['rebuild'] = TRUE;
-
   // Set Defaults for optional fields
   $details['fieldset_title'] = (isset($details['fieldset_title'])) ? $details['fieldset_title'] : 'Relationships';
   $details['additional_instructions'] = (isset($details['additional_instructions'])) ? $details['additional_instructions'] : '';
@@ -497,13 +495,12 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
   $form['relationships']['relationship_table']['new']['rel_action'] = array(
     '#type' => 'submit',
     '#value' => t('Add'),
-    '#name' => 'rel_add',
+    '#name' => 'rel-add',
     '#ajax' => array(
       'callback' => 'chado_add_node_form_relationships_ajax_update',
       'wrapper' => 'tripal-generic-edit-relationships-table',
       'effect'   => 'fade',
       'method'   => 'replace',
-      'prevent'  => 'click'
     ),
     // When this button is clicked, the form will be validated and submitted.
     // Therefore, we set custom submit and validate functions to override the
@@ -518,7 +515,6 @@ function chado_add_node_form_relationships(&$form, &$form_state, $details) {
     // No other fields will be validated (ie: no fields from the main form or any other api
     // added form).
     '#limit_validation_errors' => array(
-      array('relationships'),  // Validate all fields within $form_state['values']['relationships']
       array('relationship_table')  // Ensure relationship table results are not discarded.
     )
   );
@@ -709,6 +705,8 @@ function chado_add_node_form_relationships_add_button_submit(&$form, &$form_stat
   unset($form_state['input']['relationship_table']['new']['type_id']);
   unset($form_state['input']['relationship_table']['new']['type_name']);
 
+  // This is needed to ensure the form builder function is called to
+  // rebuild the form on ajax requests.
   $form_state['rebuild'] = TRUE;
 }
 
@@ -744,6 +742,8 @@ function chado_add_node_form_relationships_remove_button_submit(&$form, &$form_s
     }
   }
 
+  // This is needed to ensure the form builder function is called to
+  // rebuild the form on ajax requests.
   $form_state['rebuild'] = TRUE;
 }
 
@@ -849,7 +849,8 @@ function theme_chado_add_node_form_relationships_table($variables) {
 
   return theme('table', array(
     'header' => $header,
-    'rows' => $rows
+    'rows' => $rows,
+    'sticky' => FALSE
   ));
 }
 

+ 15 - 4
tripal_feature/includes/tripal_feature.chado_node.inc

@@ -231,9 +231,6 @@ function chado_feature_form($node, &$form_state) {
   );
   chado_add_node_form_dbxrefs($form, $form_state, $details);
 
-  // TODO: For some reason adding a relationship to the form breaks AJAX
-  // for features (works for other node type)... need to debug
-
   // RELATIONSHIPS FORM
   //---------------------------------------------
   $relationship_cv = tripal_get_default_cv('feature_relationship', 'type_id');
@@ -248,7 +245,6 @@ function chado_feature_form($node, &$form_state) {
   );
   chado_add_node_form_relationships($form, $form_state, $details);
 
-
   return $form;
 }
 
@@ -481,6 +477,14 @@ function chado_feature_insert($node) {
       'foreignkey_value' => $feature_id      // the value of the feature_id key
     );
     chado_update_node_form_dbxrefs($node, $details);
+
+    // * Relationships Form *
+    $details = array(
+      'relationship_table' => 'feature_relationship',
+      'foreignkey_value' => $feature_id
+    );
+    chado_update_node_form_relationships($node, $details);
+
   }
   else {
     $feature_id = $node->feature_id;
@@ -565,6 +569,13 @@ function chado_feature_update($node) {
     );
     chado_update_node_form_dbxrefs($node, $details);
 
+    // * Relationships Form *
+    $details = array(
+      'relationship_table' => 'feature_relationship',
+      'foreignkey_value' => $feature_id
+    );
+    chado_update_node_form_relationships($node, $details);
+
   }
   else {
     drupal_set_message(t('Unable to update feature.'), 'warning');