A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.laravel-enso.com/backend/forms.html below:

Website Navigation


Form Builder | Laravel Enso

# Form Builder

JSON-based Form builder for Laravel Enso

This package can work independently of the Enso ecosystem.

The front end implementation that utilizes this api is present in the forms package.

For live examples and demos, you may visit laravel-enso.com

click on the photo to view a short demo in compatible browsers

# Installation

Comes pre-installed in Enso.

To install outside of Enso:

  1. install the package composer require laravel-enso/forms

  2. if needed, publish and customize the config

  3. install the front end for the api implementation: yarn add @enso-ui/forms

# Features # Under the Hood # Usage

When using the form builder functionality, you will be needing several items:

  1. create a template file for the new form, using template.json as an example, and place it inside app/Forms (recommended). Below is an example of such a template:

When giving a number of columns, the fields will be evenly divided into columns, and will have equal width. If a custom value is given, then you may specify on each field the desired width. See below for more information.

When using the money input type, you should read the accounting.js documentation, as these details are outside of the scope of this documentation.

  1. create a Form builder class.

This class will handle the logic for creating the form configuration out of your template. If any extra logic is required to fill or process the form, in addition to the template, this is the place for it.

In the example above, you can see that for the 'roleList' form attribute we're setting the value by using a helper method on the model.

You may even use the available fluent methods to override (if necessary) default values provided in the template.

  1. in your controller methods return the resulting data from the Form builder.

In the above examples, we're using injection to create an instance of our Form builder class (UserGroupForm), equivalent to instantiating it using new inside the methods.

  1. inside your page/component import and use the VueForm component. Take a look at the forms UI package documentation for more information.
# Advanced usage

The PHP Form class provides the following fluent helper functions:

It also provides the 2 methods used for generating the properly formatted form configuration:

# Global Configuration

The Form builder can be globally configured from within its own configuration file, found at config/enso/forms.php:

The following options are available:

# Form Configuration # Root level parameters # method

If using the form normally, by calling create($model), edit($model) methods, then the action is set automatically, as "post" for creation and "patch" for edit.

# sections

All form inputs are grouped into sections. See below for the sections details.

# title

This is the title of the form.

# icon

The Font Awesome 5 icon class, for example "book" for the "fa-book" CSS class.

# routePrefix

Represents the route prefix that is used when checking permissions and building the route/path for a certain button. For example, for a user form's Save button, if the name of the store route is "administration.users.create", then the prefix is "administration.users" and the action is "create".

# routes

An object that will hold the route for each action.

# actions

The actions are used to determine the available buttons in the form. Note that if the authorize flag is set to true, the builder also checks if the user has access to/for a certain action, and if he does not, the respective button won't be shown.
If the actions are not given, defaults are used, depending on the method parameter, as follows:

# autosave

If set to true, the form will perform an auto-save when any of its inputs change

# debounce

Should be used in conjunction with autosave so that the number of requests to the backend are limited

Flag that sets whether authorization checks should be made. If not given in the form, the option is read from the global form configuration, found at config/enso/forms.php. If given, it overrides the global value.

# params

Can be used to pass extra parameters to the VueJS component / front-end, useful when customizing the form in-page (with slots, linking the form component/data to other components in the page, etc).

Notes:

# dividerTitlePlacement

It specifies the relative position of the divider. If not given, the option is read from the global form configuration, found at config/enso/forms.php

# tabs

The flag activates the tab feature of the form. This then requires that each section has a tab property which specifies the name of the tab the section belongs to.

# labels

If set to true, then placeholders will be used instead of labels.

# Section

The section is the organizing block for form inputs.

# columns

The attribute specifies how many columns will be used for the form elements in this section. If giving a number, then the size of each element is calculated automatically.

If using "custom", you need to specify for each filed the column size, by providing the column parameter (see below).

If using "slot", then a slot will be rendered for that section. In this case, you also need to specify an additional "slot": "name" parameter with the desired name of the slot.

# fields

The fields parameter will hold the actual form elements. For the configuration of each specific form element, see below.

# divider

Flag that specifies that a divider should be used here.

# title

Title for the divider. Should be used in conjunction with the divider parameters, as without setting the divider to true, the title will not be shown.

Note that the position of the divider title will depend on the value of the dividerTitlePlacement parameter (see above).

# column

Flag that specifies the column size. Only needed when the value of columns the value of "columns" is "custom".

# tab

Specifies the name of the tab this section belongs to. Each section may have its own tab or multiple sections can share a tab.

When setting this option, the tabs flag on the main template structure must be present and set to true.

# slot

Specifies the name of the slot that should be rendered for this section. Only needed when the value of "columns" is "slot".

# Field

Is the individual element of the from, generally representing an input of some sort.

# label

The label for the element.

# name

The name of the Model's attribute, that is to be mapped to this input (for instance, the name is also used to fill the models's value when setting up an edit type of form).

The name will be the request's key for the value of the input given be the user, when an action is committed (for instance the user clicks the Save button).

# value

The starting value for a form element. The value can be

# meta

Holds various mostly optional parameters that can be used to configure a form element (see Meta below.)

# column

The size of the column for that element IF using the "custom" value for section columns parameter. The given number is used in combination with Bulma's is-x 12-columns-system. See here for more information.

Note that if columns parameter is not set to "custom", the column parameter is not required and is ignored.

# Meta

Is a set of parameters used to configure the supported form elements.

# Generic # type # content

Represents the type for an HTML element, and therefore can take the expected types such as "text", "number", "date", "checkbox", "password", etc. Can also take "money" (for monetary values inputs).

# disabled

Flag that marks the disabled state for a form element.

# readonly

Flag that marks the readonly state for a form element.

# placeholder

The placeholder text used on that form element.

# tooltip

Tooltip used for that form element.

# hidden

Flag that marks the element as hidden, which means it will be rendered but will not be visible.

# custom

Flag that marks this element as as CUSTOM. What this means is that the VueJS component does not attempt to insert an component for that element, but instead renders a named slot (the name being the element's name).

This allows you to build and insert custom elements in the form, for complex scenarios.

# Select only # options

If it is an array, it will be considered to be an array of options for that select element, each object should contain an id and name label by default, for the value and label field respectively. You can modify these keys using the trackBy and label options below. If it is a simple string, it will be considered to be an Enum class name, and the builder will attempt to get the select values from the Enum.

# trackBy

Is the attribute that is to be used as identifier for each of the select options i.e. the name of the attribute that is to be used when setting the value for the 'value' attribute of an HTML <option> element.

# label

Is the attribute that is to be used as label for each of the select options i.e. the name of the attribute that is to be used when setting the value for the an HTML <option> element.

# multiple

Flag that determines the select element to accept multiple values (works as a multi-select).

# source

Flag that determines the select element to work in server-side mode, meaning that it will use the source URI in order to fetch the list of options. When using the source parameter, the options parameter is not required.

# translated

Flag that determines if the select options should be translated

# disable-clear

Flag that disables the button to clear a choice which is useful when a selected value is mandatory.

# objects

Flag that puts the select in object mode, which means that the form, instead of storing a primitive value for the selected value, stores the entire option object, which can be useful for complex scenarios

# pivotParams

Pivot params that get used when using the Select component in server-side mode and are passed along with the request, when loading or refreshing the option list.

If using the OptionsBuilder trait for the select's back-end endpoint, the pivot parameters are applied automatically.

# customParams

Custom params that get used when using the Select component in server-side mode and are passed along with the request, when loading or refreshing the option list.

On the back-end, the custom params should be read from the request and applied as required.

# Input only # step

Parameter corresponds to the step parameter for an HTML field.

# min

Parameter corresponds to the min parameter for an HTML <input> field, where the browser does a client side validation.

# max

Parameter corresponds to the max parameter for an HTML <input> field, where the browser does a client side validation.

# Datepicker & Timepicker # format

Represents the format of the date/time used for the component.

Since the flatpickr library is used, it requires its format. For more details, check the documentation .

# time

Flag that enables the time picking functionality for the datepicker, in addition to the default date functionality

# time12hr

Flag that enables the time picker to operate in 12h mode vs 24h mode.

# Textarea only # rows # resize

Specifies the number of rows for the textarea.

# Money Input # symbol

Is the current symbol to be used for a money input, for example "$".

# precision

Is the precision (decimal places) for the amount.

# thousand

Is the thousands separator for the amount.

# decimal

Is the decimal separator for the amount.

# positive

The format for positive amounts, e.g. "%s %v" See the accounting.js library for more.

# negative

The format for negative amounts, e.g. "%s (%v)" See the accounting.js library for more.

# zero

The format for zero amounts, e.g. "%s -- " See the accounting.js library for more.

# Examples

Following you will find several non-exhaustive examples, with most if not all of the types, and various parameter combinations.

# Text input

A disabled generic text input

# Numeric input

A numeric text input with a 1-5 range, and a 0.5 step when changing values

# Checkbox input

A checkbox input, with a default value of true.

# Textarea

A textarea with a placeholder and a 5 rows height. Note that the textarea is resizable only if you add the "resize": true property.

# wysiwyg

A basic what-you-see-is-what-you-get editor input.

# DatePicker

The most basic datepicker, with a placeholder.

# DatePicker with time

A datepicker also with time selection.

# Timepicker

A timepicker with a placeholder and 24 hour format time. Note that if you use a 12 hour format time, on change, in the back end, you won't be able to differentiate between AM and PM.

# Single Select

A single select, with a default non-standard option list, a set value, and custom tracking attributes.

# Server Side Select

A server side single select, that fetches the list of options using the named route given as source.

# Multi-Select

A multi select, with no default value, no options and no server-side fetching option.

In this case, you would set the options list from within your controller/service/etc by calling the options method on the form builder object:

Note: For more examples, you may look into the Enso packages for various use cases.

# Publishes # Contributions

are welcome. Pull requests are great, but issues are good too.

# License

This package is released under the MIT license.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4