Input Component API
The form_input
component is Vue.js driven child component of the matestack_form
component and is used to collect user input.
Parameters
key - required
Defines the key which should be used when posting the form data to the server.
type - required
Pass in as symbol. Defines the type of the input
. All HTML input types are supported.
placeholder
Defines the placeholder.
label
Defines the label which will be rendered right before the input tag. You can also use the label
component in order to create more complex label structures.
required
If set to true, HTML validations will be triggered on form submit.
init
If given, this value will be the initial value of the input. If used in an edit form of a given ActiveRecord model, the init value will be automatically derived from the model itself.
File Upload
Don't forget to add the multipart: true
attribute to your form_config
in order to enable file uploads!
In order to perform a single file upload, add this form_input
component
In order to perform multiple file uploads, add this form_input
component
Don't forget to add the multiple: true
attribute to your form_config
in order to enable multi file upload!
In order to accept multiple files, you should permit params on your controller like:
some_controller.rb
Please be aware that the form_input
components with a type: :file
can not be initialized with a given file.
Range Input
Whilst working similiar to the 'text' input, the range input accepts a few more parameters. It accepts also 'min', 'max', 'step', 'list' as optional parameters.
with max, min, step set
with corresponding datalist
To use a datalist for the range input specify the 'list' parameter with the id of the provided datalist
Custom Input
If you want to create your own input component, that's easily done since v.1.3.0
. Imagine, you want to use flatpickr
and therefore need to adjust the input
rendering and need to initialize the third party library:
Create your own Ruby component:
app/matestack/components/my_form_input.rb
Create the corresponding Vue.js component:
Generic code:
In order to support the flatpickr
library, you would do something like this:
app/matestack/componenst/my_form_input.js
Don't forget to require and register the custom component JavaScript according to your JS setup!
Finally, use it within a
matestack_form
:
Last updated