Field Properties

Common properties of field

Property
Default
Accepted values
Description
type
none
String
Type of field
label
none
String
Label of field
model
none
String
Name of property in the model
id
auto-generated
String
id of the field. If not set, will be auto-generated from the slugified version of either: schema.inputName, schema.label or schema.model, in that order. If the fieldIdPrefix option is set, it's value will be prepended to both manual & auto-generated ids.
inputName
none
String
set name attribute to input field. You can use it to generate normal HTML Forms and submit the field values to server-side. Example
featured
false
Boolean
is it a featured (bold) field? Can be a function too.
visible
true
Boolean
if false, field will be hidden. Can be a function too.
disabled
false
Boolean
if true, field will be disabled. Can be a function too.
required
false
Boolean
If true, Stylizes the field as required. Works in conjunction with validators.
multi
false
Boolean
if true, it will be visible only if multiple is true in component attributes
default
none
any
Default value of the field (used when creating a new model)
hint
none
String
Show this hint below the field
help
none
String
Tooltip/Popover triggered by hovering over the question icon before the caption of field. You can use HTML elements too.
validator
none
Function or Array
Validator for value. It can be an array of functions too.
none
Amount of time in milliseconds validation waits before checking, refer to validation
styleClasses
none
String or Array
Custom CSS style classes. They will be appended to the .from-group
buttons
none
Array
Array of button objects. This is useful if you need some helper function to fill the field. (E.g. generate password, get GPS location..etc)*
none
Object
See below

Common methods of field

Method
Description
get: function(model) {...}
A read formatter function where you can format the model value to the field
set: function(model, value) {...}
A write formatter function where you can format the field value to the model

Common events of field

Name
Attributes
Description
onChanged
(model, newVal, oldVal, field)
Triggered if the value of field is changed.
onValidated
(model, errors, field)
Triggered if validation of field is executed.

Example

1
{
2
type: "input",
3
inputType: "text",
4
label: "Name",
5
model: "name",
6
id: "full_name",
7
readonly: false,
8
featured: true,
9
disabled: false,
10
required: true,
11
default: "Anonymous",
12
hint: "Please enter your full name",
13
help: "This is an other longer help text",
14
validator: validators.string,
15
16
onChanged: function(model, newVal, oldVal, field) {
17
console.log(`Model's name changed from ${oldVal} to ${newVal}. Model:`, model);
18
},
19
20
onValidated: function(model, errors, field) {
21
if (errors.length > 0)
22
console.warn("Validation error in Name field! Errors:", errors);
23
}
24
}
Copied!

Dynamic visibility

With the visible, disabled, readonly and featured properties, you can also show or disable fields dynamically. Those properties can take a Function with a model parameters and expect a Boolean in return.
1
{
2
type: "select",
3
label: "Type",
4
model: "type",
5
values: [
6
{ id: "personal", name: "Personal" },
7
{ id: "business", name: "Business" }
8
]
9
},{
10
type: "text",
11
label: "Company name",
12
model: "company.name",
13
visible: function(model) {
14
//visible if business is selected
15
return model && model.type == "business";
16
}
17
}
Copied!

Generated values

For fields select, checklist, selectEx or vueMultiSelect, the values property can be a Function. In this case, you can dynamically generate the items.
1
{
2
type: "select",
3
label: "Item",
4
model: "item",
5
// values gets model and schema as parameters
6
values: function(model, schema) {
7
switch(model.category) {
8
case "Fruit": return ["Apple", "Peach", "Orange"];
9
case "Vehicle": return ["Car", "Bicycle", "Ship"];
10
case "Animals": return ["Lion", "Dog", "Cat"];
11
}
12
13
return [];
14
}
15
}
Copied!

Custom Attributes

You can add custom HTML Attributes, such as data-attributes, to fields by using an attributes object.
You can also specify the attributes of the surrounding wrapper and label:
The attributes object is broken up into "wrapper", "input" and "label" objects which will attach attributes to the respective HTML element in the component. All VFG Core fields support these, where applicable.
1
{
2
type: "input",
3
inputType: "text",
4
model: "first_name",
5
label: "First Name",
6
attributes: {
7
wrapper: { "data-toggle": "collapse" },
8
input: { "data-toggle": "tooltip", "title": "Some Tooltip to be displayed by Bootstrap Tooltips" },
9
label: { "custom-attr": "custom-value" }
10
}
11
}
Copied!
If you do not specify where the attributes go, and just provide a flat "attributes" property, then the attributes will be assigned to the "input" element on the component by default.
1
{
2
type: "input",
3
inputType: "text",
4
model: "first_name",
5
label: "First Name",
6
attributes: {
7
"data-toggle": "collapse",
8
"title": "Some Tooltip Title"
9
}
10
}
Copied!