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.7.18 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.17 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.16 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.15 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.14 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.13 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.12 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.11 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.10 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.9 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.3 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.2 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.1 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.7.0 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.38 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.37 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.36 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.35 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.34 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.33 app/javascript/controllers/fields/phone_controller.js