Form Input
The form_input
component is Vue.js driven child component of the form
component and is used to collect user input.
All child components form_*
(including this component) have to be placed within the scope of the parent form
component, without any other Vue.js driven component like toggle
, async
creating a new scope between the child component and the parent form component! Non-Vue.js component can be placed between form
and form_*
without issues!
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 - optional
Defines the placeholder.
label - optional
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 - optional
If set to true, HTML validations will be triggered on form submit.
init - optional
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
Register your component:
app/matestack/components/registry.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 the custom component JavaScript according to your JS setup!
Finally, use it within a
form
:
Last updated