Provide better instructions for using the field with form api in a custom form

Created on 25 August 2024, 4 months ago

Problem/Motivation

The annotation/instructions in the PhoneInternationalElement class for using a field in a custom form are incorrect.

 * @code
 * $form['phone'] = [
 *   '#type' => 'phone_international',
 *   '#title' => $this->t('International Phone'),
 *   '#attributes' => [
 *      'data-country' => 'PT',
 *      'data-geo' => 0, // 0(Disable) or 1(Enable)
 *      'data-exclude' => [],
 *      'data-only' => [],
 *      'data-preferred' => ['PT']
 *   ],
 * ];
 * @endcode

The settings for the field can not be added as attributes because they get overwritten in the processInternationalPhone method

Proposed resolution

Better document how to use the field with form api in a custom field, which is to use the array keys #countries, #exclude_countries, #country i.e.

* @code
 * $form['phone'] = [
 *   '#type' => 'phone_international',
 *   '#title' => $this->t('International Phone'),
 *   '#countries' => 'all',
 *   '#country' => 'uk'
 * ];
 * @endcode
📌 Task
Status

Active

Version

3.3

Component

Documentation

Created by

🇬🇧United Kingdom joehuggans Harrogate, UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @joehuggans
  • Status changed to Needs review 12 days ago
  • I have applied the changes please review it .

  • 🇬🇧United Kingdom joehuggans Harrogate, UK

    @nikarika.s - I don't think this works, because the JS in the module looks for these data attributes, so it would break the field to remove them.

    The only thing needed here is to update the annotation.

Production build 0.71.5 2024