Form.io SDK
L'SDK ha lo scopo di consentire alcuni tipi di chiamate in modo semplificato dai campi validation o campi calcolati dei moduli fatti con Form.io.
Le funzioni disponibili sono accessibili da window.FormioHelper
authenticatedCall('applications'): Promise
authenticatedCall('applications'): Promise
restituisce le pratiche dell'utente autenticato
Esempio: Settare le opzioni di una select
async function get_data() {
window.FormioHelper.authenticatedCall("applications")
.then(
function(promise) {
console.log(promise)
instance.setItems(promise.data)
})
}
if (values.length === 0) {
get_data()
}
getTenantInfo(): Promise
getTenantInfo(): Promise
restituisce le info del tenant, in particolare è utile per reperire il tenant-id
Esempio:
async function check() {
tenant = await window.FormioHelper.getTenantInfo()
if (tenant.comune === data.applicant.data.address.data.municipality) {
...
} else {
...
}
}
oppure
window.FormioHelper.getTenantInfo().then(data => {...})
getCurrentLocale(): string
getCurrentLocale(): string
restituisce la lingua corrente
Esempio:
lang = window.FormioHelper.getCurrentLocale()
if (lang === "it") {
...
} else {
...
}
getRemoteJson(url, method = 'get', headers = null): Promise
getRemoteJson(url, method = 'get', headers = null): Promise
restiuisce un json da una API remota specificando eventualmente metodo e headers custom per la chiamata
Esempio: Settare le opzioni di una select
async function get_data() {
window.FormioHelper.getRemoteJson('https://api.opencontent.it/geo/comuni')
.then(
function(promise) {
console.log(promise)
instance.setItems(promise.data)
})
}
if (values.length === 0) {
get_data()
}
oppure
window.FormioHelper.getRemoteJson('https://api.opencontent.it/geo/comuni')
.then(data => {...})
getFieldApplication():
Promise
getFieldApplication():
Promiserestituisce il valore della chiave passata come parametro dell'oggetto application di una pratica
// Esempio oggetto application
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"user": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"user_name": "string",
"service": "string",
"service_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"service_name": "string",
"service_group_name": "string",
"tenant": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"subject": "string",
"data": {},
"compiled_modules": [
{}
],
"attachments": [
{}
],
"creation_time": 0,
"created_at": "2024-05-14T08:03:14.112Z",
"submission_time": 0,
"submitted_at": "2024-05-14T08:03:14.112Z",
"latest_status_change_time": 0,
"latest_status_change_at": "2024-05-14T08:03:14.112Z",
"protocol_folder_number": "string",
"protocol_folder_code": "string",
"protocol_number": "string",
"protocol_document_id": "string",
"protocol_numbers": [
{}
],
"protocol_time": 0,
"protocolled_at": "2024-05-14T08:03:14.112Z",
"outcome": true,
"outcome_motivation": "string",
"outcome_file": {},
"outcome_attachments": [
{}
],
"outcome_protocol_number": "string",
"outcome_protocol_document_id": "string",
"outcome_protocol_numbers": [
{}
],
"outcome_protocol_time": 0,
"outcome_protocolled_at": "2024-05-14T08:03:14.112Z",
"payment_type": "string",
"payment_data": {},
"status": "string",
"status_name": "string",
"authentication": {},
"links": {},
"meetings": [
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
],
"integrations": [
{}
],
"backoffice_data": {},
"flow_changed_at": "2024-05-14T08:03:14.112Z",
"user_compilation_notes": "string",
"external_id": "string",
"geographic_areas": [
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "string"
}
],
"user_group_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"operator_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"locale": "string"
}
Esempio:
Senza nessun parametro restituisce tutto l'oggetto application
window.FormioHelper.getFieldApplication().then(data => {console.log(data)})
Con parametro restituisce il valore della chiave oggetto
window.FormioHelper.getFieldApplication('id').then(data => {console.log(data)})
getFieldMeta(): string
getFieldMeta(): string
Esempio: Recupero dato dai meta
Senza nessun parametro restituisce tutto l'oggetto meta
window.FormioHelper.getFieldMeta()
Con parametro restituisce il valore della chiave oggetto - primo livello
window.FormioHelper.getFieldMeta('legals')
Con parametro restituisce il valore della chiave oggetto - secondo livello
window.FormioHelper.getFieldMeta('legals.privacy_info')
Esempio con array
window.FormioHelper.getFieldMeta('topics[0].text')
In caso il filtro non trovi gli elementi restituirĂ false
Esempio: Popolare listo prezzi da Directus
async function get_data() {
window.FormioHelper.getRatesLists("URL_DIRECTUS",CalendarID)
.then(
function(promise) {
console.log(promise)
})
}
Per recuperare il listino prezzi ho bisogno di passare URL_DIRECTUS (https://directus-test.boat.opencontent.io/graphql) e l'ID del calendario da dove recuperare il listino prezzi
Esempio: Abilitare o disabilitare proprietĂ di un campo/i
La funzione editFormProperties(instance, edits)
serve per modificare a runtime le proprietĂ dei campi di un form Form.io.
window.FormioHelper.editFormProperties(instance, {
phone_number: {
"validate.required": false, // il campo NON è obbligatorio
},
fiscal_code: {
"validate.required": true, // il campo è obbligatorio
}
});
uoi impostare le chiavi del componente (uguali a quelle che vedi in Form.io builder → JSON editor).
label
string
Testo mostrato come etichetta del campo
description
string
Testo di supporto sotto al campo
disabled
boolean
Disabilita il campo (non editabile)
hidden
boolean
Nasconde il campo dalla vista
prefix
string
Testo/icone da mostrare prima dell’input
suffix
string
Testo/icone da mostrare dopo l’input
tooltip
string
Tooltip mostrato al passaggio del mouse
validate.required
boolean
Campo obbligatorio (true
) o facoltativo (false
)
attributes.readOnly
boolean
Rende il campo readonly
Last updated
Was this helpful?