Sha256: 0e7028529c8347c42022cf077cc9c6545fac87dc6fad81aab4f1908afe9ee741

Contents?: true

Size: 998 Bytes

Versions: 42

Compression:

Stored size: 998 Bytes

Contents

import { Controller } from "@hotwired/stimulus"
require("intl-tel-input/build/css/intlTelInput.css");
import intlTelInput from 'intl-tel-input';

export default class extends Controller {
  static targets = [ "field" ]

  connect() {
    this.initPluginInstance()
  }

  disconnect() {
    this.teardownPluginInstance()
  }

  initPluginInstance() {
    let options = {
      hiddenInput: this.fieldTarget.dataset.method,
      customContainer: "w-full",
      utilsScript: metaContent("intl_tel_input_utils_path") || `https://cdn.jsdelivr.net/npm/intl-tel-input@${window.intlTelInputGlobals.version}/build/js/utils.js`
    }

    this.plugin = intlTelInput(this.fieldTarget, options);
  }

  teardownPluginInstance() {
    if (this.plugin === undefined) { return }

    // revert to original markup, remove any event listeners
    this.plugin.destroy()
  }
}

function metaContent (name) {
  const element = document.head.querySelector(`meta[name="${name}"]`)
  return element && element.content
}

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
bullet_train-fields-1.14.0 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.13.0 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.12.3 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.12.2 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.12.1 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.12.0 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.11.0 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.10.0 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.9.0 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.8.5 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.8.4 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.8.3 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.8.2 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.8.1 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.8.0 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.23 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.22 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.21 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.20 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.19 app/javascript/controllers/fields/phone_controller.js