Sha256: fe4fd5215a797cb35bdd0bbd98906864b90b2b8fc124d0df179533ebca144ec2

Contents?: true

Size: 1.1 KB

Versions: 109

Compression:

Stored size: 1.1 KB

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"
    }

    // TODO: add instructions on how to copy this asset into the application's assets path and write the meta tag into the head (via the engine?)
    const utilsScriptPath = metaContent("intl_tel_input_utils_path")
    if (utilsScriptPath) {
      options['utilsScript'] = utilsScriptPath
    }

    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

109 entries across 109 versions & 1 rubygems

Version Path
bullet_train-fields-1.6.30 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.29 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.28 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.27 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.26 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.25 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.24 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.23 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.22 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.21 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.20 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.19 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.18 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.17 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.16 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.15 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.14 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.13 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.12 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.6.11 app/javascript/controllers/fields/phone_controller.js