Sha256: 996c24e6ccfcff79969ef2e15f38fbab1f424d3815d61ca81afb127093b7c54d

Contents?: true

Size: 1.62 KB

Versions: 14

Compression:

Stored size: 1.62 KB

Contents

import { Controller } from 'stimulus'
import StimulusReflex from 'stimulus_reflex'

/* This is your application's ApplicationController.
 * All StimulusReflex controllers should inherit from this class.
 *
 * Example:
 *
 *   import ApplicationController from './application_controller'
 *
 *   export default class extends ApplicationController { ... }
 *
 * Learn more at: https://docs.stimulusreflex.com
 */
export default class extends Controller {
  connect () {
    StimulusReflex.register(this)
  }

  /* Application wide lifecycle methods.
   * Use these methods to handle lifecycle concerns for the entire application.
   * Using the lifecycle is optional, so feel free to delete these stubs if you don't need them.
   *
   * Arguments:
   *
   *   element - the element that triggered the reflex
   *             may be different than the Stimulus controller's this.element
   *
   *   reflex - the name of the reflex e.g. "ExampleReflex#demo"
   *
   *   error - error message from the server
   */

  beforeReflex (element, reflex) {
    // document.body.classList.add('wait')
  }

  reflexSuccess (element, reflex, error) {
    // show success message etc...
  }

  reflexError (element, reflex, error) {
    // show error message etc...
  }

  afterReflex (element, reflex) {
    // document.body.classList.remove('wait')

    const focusElement = this.element.querySelector('[autofocus]')
    if (focusElement) {
      focusElement.focus()

      // shenanigans to ensure that the cursor is placed at the end of the existing value
      const value = focusElement.value
      focusElement.value = ''
      focusElement.value = value
    }
  }
}

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
stimulus_reflex-3.1.3 lib/generators/templates/application_controller.js
stimulus_reflex-3.1.2 lib/generators/templates/application_controller.js
stimulus_reflex-3.0.0 lib/generators/templates/application_controller.js
stimulus_reflex-2.2.3 lib/generators/templates/application_controller.js
stimulus_reflex-2.2.2 lib/generators/templates/application_controller.js
stimulus_reflex-2.2.1 lib/generators/templates/application_controller.js
stimulus_reflex-2.2.0 lib/generators/templates/application_controller.js
stimulus_reflex-2.1.9 lib/generators/templates/application_controller.js
stimulus_reflex-2.1.8 lib/generators/templates/application_controller.js
stimulus_reflex-2.1.7 lib/generators/templates/application_controller.js
stimulus_reflex-2.1.6 lib/generators/templates/application_controller.js
stimulus_reflex-2.1.5 lib/generators/templates/application_controller.js
stimulus_reflex-2.1.4 lib/generators/templates/application_controller.js
stimulus_reflex-2.1.3 lib/generators/templates/application_controller.js