Image Input

Options

The image input accepts the following options:

PropertyTypeDefaultDescription
uploadHandlerFunction-A function that receives the HTML5 File object as first argument and expects an src string as return value. The uploadHandler function can also be defined globally for all image uploads, see the plugin Configurationopen in new window.
multipleBooleanfalseAllow multiple images to be selected.
acceptString-A comma separated list of accepted MIME types. MDN Docsopen in new window.

Note: All other props are passed directly to the <input type="file"> element.

Examples

Below you can find some examples of the image input type.

Single Image

In its standard form the image input type allows you to upload an image and have a preview directly in the form. It only accepts one image and selecting a new one will replace the old one.

Source:

<template>
  <FormKit type="image" label="Single Image" />
</template>

Output:

No file chosen

Value:

Single Image with uploader

The image input also accepts an optional uploadHandler function. If present, the uploadHandler receives the HTML5 File object as first argument and expects an src string as return value. You can use this to upload the image to your server before the user submits the form. The uploadHandler can also be defined globally in the configuration.

Source:

<template>
  <FormKit type="image" label="Single Image" upload-handler="fakeUpload" />
</template>

Output:

No file chosen

Value:

Multiple Images

You can also upload multiple images and get a list of all selected images with previews. It is also possible to remove images from the list by clicking the remove button.

Source:

<template>
  <FormKit type="image" label="Multiple Images" multiple />
</template>

Output:

No file chosen

Value:

[]

Multiple Images with uploader

Similar to the single image with uploader the multiple image input type also accepts an uploadHandler function. It gets called asynchronously for each selected image.

Source:

<template>
  <FormKit
    type="image"
    label="Multiple Images"
    multiple
    upload-handler="fakeUpload"
  />
</template>

Output:

No file chosen

Value:

[]