0

I would like to change the help text for an input field. My form ID is views-exposed-form-events-page-1. I have a text field that I want the helpful hint to appear below. The field ID is edit-field-event-date-value2, I think, based on the HTML.

<div id="edit-field-event-date-value2-wrapper" class="views-exposed-widget views-widget-filter-field_event_date_value2">
<label for="edit-field-event-date-value2">
From </label>
<div class="views-widget">
<div id="edit-field-event-date-value2-value-wrapper">
<div id="edit-field-event-date-value2-value-inside-wrapper">
<div  class="container-inline-date"><div class="form-item form-item-field-event-date-value2-value form-type-date-popup form-group">
<div id="edit-field-event-date-value2-value"  class="date-padding"><div class="form-item form-item-field-event-date-value2-value-date form-type-textfield form-group">
<input class="form-control form-text" type="text" id="edit-field-event-date-value2-value-datepicker-popup-0" name="field_event_date_value2[value][date]" value="18/12/2019" size="20" maxlength="30" /> 
<label class="control-label element-invisible" for="edit-field-event-date-value2-value-datepicker-popup-0">Date</label>
<div class="help-block"> E.g., 18/12/2019</div>

I thought that this would work, but I'm not seeing any help text appearing under the form field.

function mytheme_form_views_exposed_form_events_page_1_alter(&$form, &$form_state, $form_id) {
  $form['edit-field-event-date-value2']['#attributes']['description'] = 'DD/MM/YYYY';
}

What am I doing wrong?

1 Answer 1

1

The description doesn't live under #attributes, but under the element directly.

So you must do something like this to get it to work:

$form['field_event_date_value2']['#description'] = 'DD/MM/YYYY';

The HTML class is not the fieldname, but rather something like field_event_date_value2 in your case.

If that is not the correct fieldname, you can try to print_r(array_keys($form)) to see if you can see what the correct name is.

4
  • Thanks, I printed the array and yes the field name is field_event_date_value2. But I can't get it to work using the above code.
    – MrFox
    Commented Dec 18, 2019 at 11:21
  • @MrFox Sorry description should be #description, I have updated my answer :)
    – user72672
    Commented Dec 18, 2019 at 11:44
  • Strangely that doesn't work either. I'm wondering if my function name is incorrect.
    – MrFox
    Commented Dec 18, 2019 at 15:52
  • You can try to write a mytheme_form_alter and dump the $form_id to see what the form ID is for the form you try to alter.
    – user72672
    Commented Dec 18, 2019 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.