0

First of all: I already tried this answer: Using jquery in Ember-cli which seems to be the canonical way of adding a jQuery plugin to ember.

I was following this tutorial: http://beerlington.com/blog/2015/01/22/jquery-inputmask-user-experience-in-emberjs/

I installed the plugins using bower, and then added the imports to Brocfile.js.

Here's my Brocfile.js:

/* global require, module */

var EmberApp = require('ember-cli/lib/broccoli/ember-app');

var app = new EmberApp({
  compassOptions: {
    outputStyle: 'expanded'
  }
});

app.import('bower_components/ember-uploader/dist/ember-uploader.js');
app.import('bower_components/moment/moment.js');
app.import('bower_components/jquery.inputmask/dist/jquery.inputmask.bundle.min.js');

module.exports = app.toTree();

The components are all correctly located at their import paths thanks to bower.

And here's the component at components/input-mask.js:

import Ember from 'ember';

export default Ember.TextField.extend({
  initializeMask: function() {
    var mask = this.get('mask');

    this.$().inputmask(mask, {
      onBeforeMask: function(value) {
        if (mask === 'mm/dd/yyyy') {
          return moment(new Date(value)).format('L');
        }
      }
    });

    // The input mask changes the value of the input from the original to a
    // formatted version. We need to manually send that change back to the
    // controller.
    this.set('value', this.$().val());
  }.on('didInsertElement')
});

But in Chrome's console I get the error: Uncaught TypeError: undefined is not a function for this.$().inputmask.

Am I missing something else to import a plugin to jQuery?

Community
  • 1
  • 1
jrlainfiesta
  • 105
  • 1
  • 2
  • 9

1 Answers1

0

The problem was solved after I restarted my computer and issued ember serve again. I guess my computer was doing something weird caching where it shouldn't have.

jrlainfiesta
  • 105
  • 1
  • 2
  • 9
  • 2
    After adding the file paths to your Brocfile.js, did you close the ember server, the start again? You need to do that every time you alter that file so the changes are picked up. – ToddSmithSalter Mar 06 '15 at 23:25