Problem/Motivation

I am trying to use the Telephone International Widget for Commerce 2.x checkout on Drupal 8.7.3. It appears the widget works for the first instance of the phone number field. The second (in the billing info) doesn't have the Country selection Flag.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

johnpicozzi created an issue. See original summary.

skymen’s picture

StatusFileSize
new5.61 KB

I fixed this issue for me. Also I have implemented function witch allow entering in the input field only symbols from phone number (digits, +, -, ()). Format of JS changed to ECMAScript 6.

skymen’s picture

Status: Active » Needs review
hotwebmatter’s picture

Code looks good. RTBC+1

johnpicozzi’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +ContributionWeekend2020

Tested it and this works way better! RTBC +1

jcmartinez’s picture

The patch #2 didn't work for me when editing a page that has two phone numbers.
Probably works when creating a page, but it didn't work for me when editing.

jcmartinez’s picture

Status: Reviewed & tested by the community » Needs work
dasginganinja’s picture

I can confirm what jcmartinez says in #6. When I have two separate fields, phone and fax, on the same edit page they seem to conflict and they switch back and forth with losing the country code / which field passes validation.

jcmartinez’s picture

I'm guessing that these two issues may be related.

kerasai’s picture

Status: Needs work » Needs review
StatusFileSize
new6.92 KB

Hi folks,

I've added to the patch from #2 to address this multiple values issue as well as the issue reported on #3143446: Flag not selected on node editing form forces user to re-select which deals with initializing the input when the value is being edited.

There is some sketchy stuff in the JS for this, which I've tried to clean up just enough to make things work and a bit more standard for Drupal use. The crux of the functionality remains as-is. Long term, I think it may make more sense to provide a @Element plugin for providing the input as a first-class form element.

Change Summary

  • Incorporates all changes from #2
  • Added a "display" textfield element to the widget to use w/JS input (described below)
  • Refactored JS to utilize jQuery in attach behavior, targeting the context (newly-added page content) only
  • JS fix for preventing re-initialization of the intlTelInput, which was breaking reordering of field values
  • Changed the "value" input to be a plain text field input for non-JS input, converted to a hidden input when JS initializes
  • Implemented "display" input as hidden by default, shown and given the intlTelInput when JS initializes
  • Implemented JS functionality to update hidden "value" input with value of "display" input as it's updated

Testing Instructions

  1. Create new content with a telephone field
  2. Edit and existing value for a telephone field
  3. Create new content with a multi-value telephone field
  4. Edit and existing value for a multi-value telephone field
  5. Reorder (and edit?) a multi-value telephone field
  6. Verify validation via constraint (is using telephone_validation)
  7. Else?
kerasai’s picture

StatusFileSize
new7.58 KB
new2.08 KB

Another adjustment, this time to the libraries handling.

I've got some fairly complicated forms, lots entities embedded within entities (IEF) and a lot of AJAX updates, and I was running into an issue with the ITI library initializing. Tracked it down to the utils.js helper library not being loaded.

This change includes utils.js as a part of the library definition and removes it from the ITI initialization option. I've also created a second library definition to be used for the module's JS that depends on the ITI library.

kerasai’s picture

Found another issue caused by copying the widget's $element form array, causing a duplicate "value" for the field.

Attached is a patch to correct this.

jollysolutions’s picture

Status: Needs review » Needs work

I tried the patch in #12 and was getting the telephone fields duplicated.

nginex’s picture

Version: 8.x-1.x-dev » 2.0.x-dev
Assigned: Unassigned » nginex

nginex’s picture

Assigned: nginex » Unassigned
Status: Needs work » Needs review

Did not check previous patches, just used core/once to handle the issue with multiple fields, tested on real project, works like a charm

ahmad khader’s picture

I tested the patch mentioned in #12, and it was successful for me. However, I believe we should format the hiddenInput to INTERNATIONAL rather than E164, as the placeholder suggests the presence of spaces.

It would be nice if in the future we added a format option to display the field

ahmad khader’s picture

StatusFileSize
new7.79 KB

Reset of code of #17

jcandan’s picture

StatusFileSize
new2.77 KB
jcandan’s picture

StatusFileSize
new3.19 KB
jcandan’s picture

StatusFileSize
new571 bytes
jcandan’s picture

I think I see what happened. It seems Ahmad's #17 patch mistakenly missed somethings, #18 is a re-roll of #12 with his desired change to INTERNATIONAL format rather than E164.

jcandan’s picture

This is a big undertaking. While I do believe it is ideal to tackle issues distinctly, the frequency of updates to this module has made it such that a big change affecting multiple bugs is inevitable. I will review this further. I plan to add tests as described in #10. Thanks, everyone.

avpaderno’s picture

Issue tags: -Commerce 2.x (duplicate) +Commerce 2.x
jcandan’s picture

Issue tags: -Commerce 2.x +Commerce 2.x (duplicate)

Option 1: intlTelInputWithUtils
If you're not concerned about filesize (e.g. you're lazy loading this script), the easiest thing to do is to just use the full bundle (/build/js/intlTelInputWithUtils.js), which comes with the utils script included. This script can be used exactly like the main intlTelInput.js - so it can either be loaded directly onto the page (which defines window.intlTelInput like usual), or it can be imported like so: import intlTelInput from "intl-tel-input/intlTelInputWithUtils".
-- https://github.com/jackocnr/intl-tel-input?tab=readme-ov-file#loading-th...

Given this is loaded when the widget is used, let's adopt the above implementation in lieu of the changes made from #11.

jcandan’s picture

Never mind. That intlTelInputWithUtils.js doesn't even come with the package. Must be outdated docs.

avpaderno’s picture

Issue tags: -Commerce 2.x (duplicate) +Commerce 2.x

The issue tag for Commerce is Commerce 2.x. Since somebody used another tag, that has been renamed Commerce 2.x (duplicate) to make clear it should not be used.

jcandan’s picture

Got a test added and refactored the work from the above patches and MR !8. Good job and thanks , everyone.

jcandan’s picture

Status: Needs review » Fixed
johnpicozzi’s picture

Gave folks from above Credit for this issue. @jcandan any reason not to give folks credit?

johnpicozzi’s picture

Sorry my above comment had a typo and sounded really rude. It was supposed to say "gave" not "give" (now fixed). Turns out I can't give Credit. @jcandan can we give folks credit for working on this issue?

jcandan’s picture

Absolutely! Thanks for calling that out, @johnpicozzi. I'll take a moment to look through the other tickets which may have influenced the total sum of changes captured here. Thanks everyone for your patches, MRs, and review.

johnpicozzi’s picture

Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.