New Metronic Docs!Added Integration Docs with Starter Kits Apps for Laravel, Laravel Livewire, Angular, Vue, Symfony, Blazor Server, Django & Flask & more
Browse Docs

Image Input not working


Not sure if the correct place is here, or in the KtUI github. Posting on both.


The image input component is not working as expected.

Selecting a new image will *not* change the value of the input field.
So the image is not sent to server.

You can verify that on the browser console.

```
// After selecting a file,
let input = document.querySelector('input[type="file"]');
console.log(input.value);
```

The current implementation will give an empty string, not the file path.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (3)


Hi

Please pull the latest from the main branch

https://github.com/keenthemes/ktui/commit/ca71aa330fbe98db9680e6ea0167f5fbc7405e7c

Thanks



Hi Vinícius Arantes

Sorry for the delay. The KTUI Image Input component is designed primarily for preview functionality and intentionally clears the file input value after processing.

Workaround Solutions: Use FormData with File Reference

// Get the KTUI Image Input instance
const imageInput = KTImageInput.getInstance(document.querySelector("[data-kt-image-input]"));

// Access the file input element directly before form submission
const fileInput = document.querySelector("input[type="file"]");
const formData = new FormData();
formData.append("image", fileInput.files[0]);



Hello Faizal.

Thank you so much for taking the time to respond!

I appreciate the proposed workaround, but unfortunately, it hasn't worked for me. After I select the image, the field clears itself, which is a bit frustrating.

Even when I create a new FormData before submitting the form, fileInput.files[0] still comes up as undefined.

I understand that this component is meant to provide an image preview, but the fundamental function of being able to upload the file is really important too.

I look forward to a proper fix for this bug.

Thanks once again for your help!


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(