Reputation: 301
I am using form.io and angular 10.
I was able to create a demo project of form.io in the angular cli .
I was also able to create a custom component as well and set my own editForm for the component.
import { Injector } from '@angular/core';
import { FormioCustomComponentInfo, registerCustomFormioComponent } from 'angular-formio';
import { AggridWrapperComponent } from './aggrid-wrapper.component';
export function minimalEditForm() {
return {
components: [
{ key: 'type', type: 'hidden' },
{
weight: 0,
type: 'textfield',
input: true,
key: 'label',
label: 'Label',
placeholder: 'Label',
validate: {
required: true,
},
},
{
weight: 10,
type: 'textfield',
input: true,
key: 'key',
label: 'Field Code',
placeholder: 'Field Code',
tooltip: 'The code/key/ID/name of the field.',
validate: {
required: true,
maxLength: 128,
pattern: '[A-Za-z]\\w*',
patternMessage:
'The property name must only contain alphanumeric characters, underscores and should only be started by any letter character.',
},
},
{
weight: 20,
type: 'textfield',
input: true,
key: 'customOptions.myOption',
label: 'My Custom Option',
placeholder: 'My Custom Option',
validate: {
required: true,
},
},
],
};
}
const COMPONENT_OPTIONS: FormioCustomComponentInfo = {
type: 'myaggrid',
selector: 'my-grid',
editForm:minimalEditForm,
title: 'agGrid',
group: 'basic',
icon: 'fa fa-star',
};
export function registerAgGridComponent(injector: Injector) {
registerCustomFormioComponent(COMPONENT_OPTIONS, AggridWrapperComponent, injector);
}
Overall the form.io builder gives a lot of components to drag and drop .
But in fact I need a small number of components and in each component reduce the number of attributes/properties or set my own properties.
I try like this but not work
<form-builder [form]='{
"title": "My Test Form",
"components": [
{
"type": "textfield",
"input": true,
"tableView": true,
"inputType": "text",
"inputMask": "",
"label": "First Name",
"key": "firstName",
"placeholder": "Enter your first name",
"prefix": "",
"suffix": "",
"multiple": false,
"defaultValue": "",
"protected": false,
"unique": false,
"persistent": true,
"validate": {
"required": true,
"minLength": 2,
"maxLength": 10,
"pattern": "",
"custom": "",
"customPrivate": false
},
"conditional": {
"show": "",
"when": null,
"eq": ""
}
},
{
"type": "textfield",
"input": true,
"tableView": true,
"inputType": "text",
"inputMask": "",
"label": "Last Name",
"key": "lastName",
"placeholder": "Enter your last name",
"prefix": "",
"suffix": "",
"multiple": false,
"defaultValue": "",
"protected": false,
"unique": false,
"persistent": true,
"validate": {
"required": true,
"minLength": 2,
"maxLength": 10,
"pattern": "",
"custom": "",
"customPrivate": false
},
"conditional": {
"show": "",
"when": null,
"eq": ""
}
},
{
"input": true,
"label": "Submit",
"tableView": false,
"key": "submit",
"size": "md",
"leftIcon": "",
"rightIcon": "",
"block": false,
"action": "submit",
"disableOnInvalid": true,
"theme": "primary",
"type": "button"
}
]
}' (change)="onChange($event)" language="he"></form-builder>
How can i define my own list of components and configure attribures/properties in each components?
Upvotes: 0
Views: 2890
Reputation: 301
By using the [option] attribute in form-builder it is possible to determine the list of components and also change the language.
example in angular-formio set language in FormBuilder
Upvotes: 1