Hi! Any way to add spellcheck="true" for all inputs?

Comments

Chi’s picture

Category: Feature request » Support request

You can implement hook_field_widget_WIDGET_TYPE_form_alter and add spellcheck attribute to required subfields.

UksusoFF’s picture

What's WIDGET_TYPE for textfield_&_textarea widget?

Chi’s picture

The type evidently is textfield_&_textarea. However the function cannot be called hook_field_widget_textfield_&_textarea_form_alter because PHP does not support ampersands in function name. So use HOOK_field_widget_form_alter with custom condition.

UksusoFF’s picture

So i need check isset ($element['first']) or isset ($element['second']) for detect double field? Or maybe proper way for this?

function HOOK_field_widget_form_alter(&$element, &$form_state, $context) {
    if ( isset ($element['first']) || isset ($element['second']) ) {
      if ( ($element['first']['#type'] == 'textfield') || ($element['first']['#type'] == 'textarea') ) {
         $element['first']['#attributes']['spellcheck'] = 'true';
      }
      if ( ($element['second']['#type'] == 'textfield') || ($element['second']['#type'] == 'textarea') ) {
         $element['second']['#attributes']['spellcheck'] = 'true';
      }
    }
}
Chi’s picture

/**
 * Implements hook_field_widget_form_alter().
 */
function HOOK_field_widget_form_alter(&$element, &$form_state, $context) {
  if ($context['instance']['widget']['type'] == 'textarea_&_textarea') {
    $element['first']['#attributes']['spellcheck'] =
    $element['second']['#attributes']['spellcheck'] = 'true';
  }
}

UksusoFF’s picture

Status: Active » Closed (works as designed)

Thanks!