alessiomaffeis / vue-picture-input

Mobile-friendly picture file input component for Vue.js 2-3 with image preview, drag and drop, EXIF orientation, and more
MIT License
888 stars 156 forks source link

How to make a permanent image by default? #153

Closed maaxim-one closed 1 year ago

maaxim-one commented 2 years ago

Let's imagine a situation: There is a picture that becomes the default :prefill="brand.book_device_brand_photo". The user chose a different picture, but changed his mind and deleted the one he chose. After deleting, you need the image :prefill="brand.book_device_brand_photo" to come back.

alessiomaffeis commented 2 years ago

Yes, I agree, this is not the intended behaviour. Please feel free to submit a PR, if you have a solution! :)

tyrrminal commented 2 years ago

In the meantime, I came up with a workaround, since there's a watch on prefill:

<picture-input 
  ref="photoInput" 
  :removable="true" 
  @remove="revert" 
  :prefill="defaultImage" 
  :customStrings="{remove:'Revert Image'}" />

Then

methods: {
  revert: function() {
    this.$refs.photoInput.prefill = null;
    this.$nextTick(function() {
      this.$refs.photoInput.prefill = this.defaultImage;
    });
  }
}
alessiomaffeis commented 1 year ago

In the meantime, I came up with a workaround, since there's a watch on prefill:

<picture-input 
  ref="photoInput" 
  :removable="true" 
  @remove="revert" 
  :prefill="defaultImage" 
  :customStrings="{remove:'Revert Image'}" />

Then

methods: {
  revert: function() {
    this.$refs.photoInput.prefill = null;
    this.$nextTick(function() {
      this.$refs.photoInput.prefill = this.defaultImage;
    });
  }
}

Yeah, I think this workaround is unfortunately the best answer, as I've found more use cases for which is not desirable to change the current behaviour.