How to work with OP Forms?
Objective
The purpose of this functionality is to support the development of Web applications with a NoCode approach within Onesait Platform. Thus, from the Control Panel you will be able to create forms, assign Entities (and datasources) to them and navigate between forms.
These forms can be integrated into your Web application, whatever UI technology you use, for example in Platform dashboards or ODS Vue applications.
To build this functionality we have based on http://Form.iowhich is a JavaScript library that includes a Builder and a Renderer, and we have extended it and integrated it with the platform capabilities allowing to easily manage the platform Entities and their DataSources.
Main functionality
List of OP Forms
A new entry has been added to the Control Panel menu:
This gives access to the list of forms:
From this list you have access to the following options:
Form search: From the magnifying glass you can search in the list.
Form creation: This button allows access to the creation screen.
View: This button gives access to the data loading screen and form view.
Editing: This accesses the form editing screen.
Deleted: with this it will be deleted.
Cloning: This button allows you to clone a form.
Creating an OP Form
After accessing with the create button from the list, the form creation screen appears.
You can follow the tips to elaborate the form.
The necessary steps would be:
Give a name to the form.
Select the entity where the records created from the form will be stored.
Drag from the left panel of components to the canvas the necessary elements to compose the form. Ideally, first drag components from the layout to give the designed structure and then drag the different elements such as text fields, selection fields, .....
While dragging the different elements, a modal window is displayed. For example, this is the one for the text field.
It has two sections, the left one for configuration and the right one for preview. Everything is done by drag and drop and filling in the properties of the components. By hovering the cursor over the question mark symbols, a tooltip will be displayed, which will guide the users to know how each field works.
Finally pressing the CREATE button will create a new form.
Form generation for an entity
In both the form creation and form editing screens there is a Build form from entity button, which after selecting an entity will generate the fields of the relevant type in the form for each field of the entity.
For example, for the entity HelsinkiPopulation whose fields are all of type number, this would be the result:
This would be one of the fields:
Data loading
From the list, clicking on the VIEW button of any of the forms takes you to the display and data loading screen.
In this screen you will first see the empty form and a space with tips for the user and links to documentation to facilitate its use.
The form can be filled in from this screen and sent to register the data in the entity defined for the form.
Navigating between forms
Buttons can be assigned different actions in the Display tab, one of them is the submission of the form submit.
To continue with the non-code practices of the platform, the form buttons have been improved by adding the Redirect field, which, after successful submission of the form data, will load the url indicated in this field on the current page.
Â
This field can be written in two ways: the complete url host + path as <https://<instance> onesaitplatform.com>/path or only the path as /path, this last one in case we are working in an application where you have defined the variable "appbase".
Loading data in a combo (SELECT)
There are many ways to load data into the SELECT component but the simplest way is to use Onesait Platform datasources.
For this, first the datasource is created. These are queries on one or several entities.
Then the SELECT is dragged on the form and the window with the configuration appears:
Go to the "Data" tab and:
In the "Data Source Type" field the value "Datasource" is selected.
“Datasource" field, the name of the datasource in this case would be catalog.
“Value Property", the value of each option of the selector, must match the path of the elements returned by the datasource for example:
If the elements returned by the datasource have this form:
{catalog:{name: "indef001",description: "permanent contract"}}}
to use as value name would be populated with catalog.name
In "item Template" you fill in the description. As before, the complete path must be filled in, for the description you would put for example the most basic form:
<span>{{ item.catalog.description }}</span>
Finally, in the "API" tab, "Property Name" must be filled in with the path of the entity property where the selection will be stored.
Loading data into a SELECT for expert users
For more expert users, it is possible to use the Platform datasources in a predefined JavaScript function that allows the operations project, filters, group, sort, offset, limit, param. This allows, without modifying the datasource, to obtain the data in the desired form by projecting the fields, sorting them, ....
This is achieved by accessing the Data tab in the Data Source Type Field, select the Custom value, then appears the Custom Values field which you must fill with this function:
from('catalogo').exec().then(function( msg ) {
values = msg.map((x) => x.catalog) ;
instance.setItems(values);
});
Where 'catalog' would be the name of the datasource that is intended to be used to obtain the data.
The rest of fields as in the previous basic load.
Tips for users
Both the creation screen and the view screen have a space where tips are displayed to make it easier for users to create forms.
Internationalization
It is possible to internationalize the forms in a simple way. To do this, a previously defined internationalization must be selected.
These internationalizations are defined from this menu entry.
Core Technology
OP Forms are based on the open-source Formio.js technology, which is a Javascript library that includes a Form Builder for the creation of forms.
Â
And a renderer and SDK that allows rendering of JSON schema forms produced by http://Form.io within your application using plain JavaScript, as well as providing a front-end SDK for communicating with the http://Form.io.
Numerous examples are also included: JavaScript Powered Forms and Form.io SDK and documentation on its use:https://help.form.io/developers/form-development/form-renderer