Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Input addEventListener doesn't work on change

please help me out in this. I am trying to save profile picture but the input.addeventlistener doesn't files on change. I am using vue with rails

This is the mount hook in when in a vue component where I want to trigger the eventlistener.

    mounted() {
    debugger
    this.previewUrl = this.placeholder;
    
    const input = this.$refs.inputSlot.querySelector('input[type="file"]')
    if (input) {
      input.addEventListener('change', event => {
        if(input.files[0]){
        const fakeFilePath  = event.currentTarget.value
        if (input.files[0].size > this.sizeLimit) {
          alert(this.$t('error.file_size', { max_size: this.maxSize }));
          input.value = '';
        } else {
          this.fileName = input.files[0].name

          if (this.preview == 'image') {
            const reader = new FileReader();
            reader.onload = event => {
              this.selectedFile = this.oldImage = this.previewUrl;
              this.previewUrl =  event.target.result;
              this.choosenFile = fakeFilePath;
            };
            reader.readAsDataURL(input.files[0]);
          }
        }
      }
      })
    }
  }

This is the input field

<input accept="image/jpeg,image/png,.jpeg" type="file" name="user[profile_picture]" id="user_profile_picture">

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can simply add @change="save" attribute to your input and after file change save method will gets triggered

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!