File Inputs and Image Inputs
Before using these components, make sure @javaabu/js-utilities
is installed and updated to the latest version. Also remember to add the necessary sass.
// for Bootstrap 5 (add a partial named web/_fileinput.scss)
@import '@javaabu/js-utilities/src/scss/bootstrap-5/fileinput';
// for Material Admin 2.6 (replace the contents of your admin/_fileinput.scss)
@import '@javaabu/js-utilities/src/scss/material-admin-26/fileinput';
File Inputs
This component renders a jasny-bootstrap
fileinput.js
powered file input that supports spatie/laravel-medialibrary
. This component requires spatie/laravel-medialibrary
.
<x-forms::form :model="$article">
<x-forms::file name="attachment" type="document" />
</x-forms::form>
File inputs supports the following attributes:
'name'
- (Required) The name of the file input.'label'
- The input label. If not provided, will be auto generated using the name.'type'
- The file type or an array of types fromAllowedMimetypes
fromjavaabu/helpers
. Defaults to'document'
.'mimetypes'
- An array or single allowed mimetype. If not provided, the giventype
will be used to determine the allowed mimetypes. Used in theaccept
attribute of the file input.'extensions'
- An array or single allowed extension. If not provided, the giventype
will be used to determine the allowed extensions. Used in the file hint.'max-size'
- The maximum allowed file size in KB. If not provided, the giventype
will be used to determine the allowed size. Used in the file hint.'collection'
- The media collection name when usinglaravel-medialibrary
. By default, thename
is used as the collection name.'conversion'
-laravel-medialibrary
media conversion to use for the displayed file url. By default, no conversion is used.'file-input-class'
- Additional CSS class to use on the fileinput div.'clear-icon'
- Icon to use on the clear file button. By default, uses the framework specific icon from config.'download-icon'
- Icon to use on the download file button. By default, uses the framework specific icon from config.'model'
- The model to bind to. By default, uses the currently bound model.'default'
- The default file url or Media object. Can be used to manually set a value to the file input.'show-hint'
- Whether to show a help text that shows the allowed file extensions and the max file size.true
by default. To display a custom message, can use thehelp
slot.'show-errors'
- Whether to show any associated validation errors.true
by default.'show-label'
- Whether to show the input label.true
by default. Iffalse
the component will be rendered without aform-group
.'required'
- Whether the input is required.false
by default.'disabled'
- Whether the input is disabled.false
by default.'ignore-accessor'
- Whether to ignore model accessors when finding the bound media. If true, will only use thegetMedia
method to find the media. This can be useful if the model has an accessor as the same name as the collection which returns a default url when the file is not present.false
by default.'inline'
- Whether to dispaly the label inline.false
by default.'framework'
- Which CSS framework to use. Defaults to the framework set in config.'upload'
- Whether to usefileUploadInput
module from@javaabu/js-utilities
. Defaults tofalse
.'upload-icon'
- Icon to display in the upload button. Defaults to the framework specific icon from config.
File Upload Inputs
This component uses fileUploadInput
module from @javaabu/js-utilities
to upload the selected file through ajax. The file will get uploaded to the parent form's action url, using the parent form's submit method. This component will only work within a form element. This is just a wrapper for the file
component with the upload
attribute set to true.
<x-forms::form :model="$article">
<x-forms::file-upload name="attachment" type="document" />
</x-forms::form>
Image Inputs
Image inputs work similar to file inputs, with a few extra attributes that allow customizing the preview of the selected image.
<x-forms::form :model="$article">
<x-forms::image name="featured_image" conversion="preview" width="500" height="500" />
</x-forms::form>
Here are the additional attributes supported by image inputs:
'icon'
- Icon to display in the image preview when no image is selected. Defaults to the framework specific icon from config.'width'
- The recommended width for the image in pixels. Defaults to400
.'height'
- The recommended height for the image in pixels. Defaults to400
.'cover'
- Whether the preview image should cover the full preview window. Defaults tofalse
.'fullwidth'
- Whether the preview window should take the full available width. Defaults tofalse
.'circle'
- Whether the preview window should be displayed as a circle. Defaults tofalse
.'aspect-ratio'
- Which aspect ratio to use as number between0.0
and1.0
. If using thecircle
option, will be forced to1.0
. Defaults to the aspect ratio of givenheight
andwidth
.'maintain-aspect-ratio'
- Whether the preview window should maintain the given aspect ratio. Defaults totrue
.
Image Upload Inputs
This is just a wrapper for the image
component with the upload
attribute set to true and works similar to the file-upload
component.
<x-forms::form :model="$article">
<x-forms::image-upload name="featured_image" conversion="preview" width="500" height="500" />
</x-forms::form>