Skip to content

A Drupal 10 module has a custom form with an example of a custom autocomplete form element.

Notifications You must be signed in to change notification settings

code-rider/d10_custom_form_autocomplete

Repository files navigation

Drupal 10 Custom Auto-complete Form

A module with a custom form with an example of Drupal 10 autocomplete form element

Instructions

In this example of a module, we are assuming we have a Taxonomy vocabulary created with machine name distributions change this name as per your need in FormAutoComplete.php and MyCustomAutocompleteForm.php

Sample

$form['field_one'] = [
  '#title' => 'Field type entity_autocomplete',
  '#type' => 'entity_autocomplete',
  '#target_type' => 'taxonomy_term',
  '#selection_settings' => [
    'target_bundles' => array('distributions'),
  ],
  '#tags' => TRUE,
  '#default_value' => "",
  '#attributes' => [
    'placeholder' => t('Select Distribution'),
    'data-disable-refocus' => "true"
  ]
];

After installation of the module, you can view this form at this URL

youe-site/custom-autocomplete-form-display

About

A Drupal 10 module has a custom form with an example of a custom autocomplete form element.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages