Sha256: 39059cea537c437ae0717a06b736ebb8968e5ddd005db1ff2b833c7fb0b5e252

Contents?: true

Size: 897 Bytes

Versions: 3

Compression:

Stored size: 897 Bytes

Contents

import { Controller } from "stimulus"
import '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() {
    this.plugin = intlTelInput(this.fieldTarget, {
      hiddenInput: this.fieldTarget.dataset.method,
      // See `config/webpack/environment.js` for where we copy this into place.
      // TODO Wish we could somehow incorporate webpacker's cache-breaking hash into this. Anyone know how?
      utilsScript: "/assets/intl-tel-input/utils.js",
      customContainer: "w-full"
    });
  }

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bullet_train-fields-1.0.2 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.0.1 app/javascript/controllers/fields/phone_controller.js
bullet_train-fields-1.0.0 app/javascript/controllers/fields/phone_controller.js