Change input event not fire?


#1

my code:
Template.settings.events({

  // i tried with 'change #fileInput': function(e) { ... } but not work too.
  'change input[type=file]': function(e) {
    console.log(e);
    alert('ok');
}
});

template:
<input type="file" id="fileInput" name="file" class="form-control file" >

what hapend ? please help !


#2

It should work so you’ll have to debug elsewhere in your code. Here’s a quick repro showing it working:

  1. meteor create input-test

  2. Replace client/main.html with:

<body>
  <form>
    <input type="file" id="fileInput" name="file" class="form-control file" >
  </form>
</body>
  1. Replace client/main.js with:
import { Template } from 'meteor/templating';
import './main.html';

Template.body.events({
  'change input[type=file]'(event) {
    console.log(event);
  },
});

Output:


#3

i see the problem: i use this package: useful:forms
this override event, so it not work !

import { Forms } from 'meteor/useful:forms';
Forms.mixin(Template.settings);

thanks @hwillson so much !