CommentFileSizeAuthor
#1 editablefields-1-save-close.patch1.52 KBkingdee40
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kingdee40’s picture

Component: Miscellaneous » Code
Category: support » bug
Status: Active » Needs review
FileSize
1.52 KB

Added cancel button via javascript.

rosemberg’s picture

kingdee40, thank you so much!

Worked fine here. Just needed a little customization to be more close to my needs (cancel button appearing only in editing state) but I think the patch you've posted will help a lot the major use cases.

rosemberg’s picture

Issue summary: View changes

typo

romaingar’s picture

Issue summary: View changes

Hello just in case you would like to perform a cancel button without reload the page as the solution #1


function mymodule_form_alter(&$form, &$form_state, $form_id) {
if (preg_match('/^editablefields_form_/', $form_id)){
    $edit_mode_state = _editablefields_get_edit_mode($form_state, $form['#parents']);
    $edit_mode = empty($display['settings']['click_to_edit']) || $edit_mode_state;
    if ($edit_mode && isset($form_state["field"])) {
     $wrapper_id = $form['actions']['submit']["#ajax"]["wrapper"];
      $ajax = array(
        'callback' => 'editablefields_form_update',
        'wrapper' => $wrapper_id,
        'effect' => 'fade',
        'event' => 'click',
        'progress' => array(
          'type' => 'throbber',
          'message' => t('Please wait'),
        ),
      );
$form['actions']['cancel']=array(
            '#name' => 'cancel-' . implode('-', $form['#parents']),
            "#type"=>"submit",
            "#executes_submit_callback"=>true,
            "#attributes"=>array("class"=>array("btn","btn-default","btn-sm","editable-cancel")),
            '#ajax'=>$ajax,
            '#submit'=>array("mymodule_form_editablefield_cancel"),
            '#limit_validation_errors' => array($form['#parents']),
            "#icon"=>"glyphicon-remove",
            );
   }
 }
}
/**
 * Form submit callback: save the field modifications.
 */
function mymodule_form_editablefield_cancel(&$form, &$form_state) {
  _editablefields_set_edit_mode($form_state, FALSE, $parents);
  $form_state['rebuild'] = TRUE;
}
sistro’s picture

Very useful... but the patch fails with latest dev version.

Romaingar solution is for a custom module, right?

Gunfigter100’s picture

Romaingar's answer proved very helpful. Two notes about it though. The variable $display is not set anywhere in the provided code. It appears to be a reference to the $display argument in editablefields_form() which is then hooked by this function. I accessed this variable in my hook_form_alter() function by setting $display = $form_state['build_info']['args'][5] as this appears to hold the values sent to the originating function. Secondly, there is no #value attribute set in the $form['actions']['cancel'] array so the new button appeared as a blank button or as just a sliver of a button depending on the theme I was using.