You are here

function _comment_goodness_disable_actions in Comment goodness 7

Helper function to disable the form submit actions while the comment body is empty.

1 call to _comment_goodness_disable_actions()
comment_goodness_form_comment_form_alter in ./comment_goodness.module
Implements hook_form_FORM_ID_alter().

File

./comment_goodness.module, line 421
Comment goodness provides newest to oldest comment sorting

Code

function _comment_goodness_disable_actions(&$form) {
  $node_language = $form['#node']->language;
  $disable_button_state = array(
    'disabled' => array(
      "textarea[name=\"comment_body[{$node_language}][0][value]\"]" => array(
        'empty' => TRUE,
      ),
    ),
  );
  foreach (array(
    'submit',
    'preview',
  ) as $button) {
    if (!isset($form['actions']['preview']['#states'])) {
      $form['actions'][$button]['#states'] = array();
    }
    $form['actions'][$button]['#states'] += $disable_button_state;
  }

  // Add css to indicate that the buttons are disabled.
  $module_path = drupal_get_path('module', 'comment_goodness');
  drupal_add_css("{$module_path}/css/disabled_actions.css");
  drupal_add_js("{$module_path}/comment_goodness.js");
}