Created
June 29, 2018 19:29
-
-
Save travist/c258516cc150b253d4b69ac4196aff27 to your computer and use it in GitHub Desktop.
Angular Form Builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default class MyComponent { | |
| this.builderForm = {components: []}; | |
| this.builderReady = false; | |
| this.builderOptions = { | |
| builder: { | |
| resource: {} | |
| } | |
| }; | |
| constructor() { | |
| var formio = (new Formio('https://humanresources.form.io')); | |
| formio.loadForms({ | |
| params: { | |
| type: 'resource', | |
| select: '_id,title,name,components', | |
| limit: 100 | |
| } | |
| }).then(function(resources) { | |
| var resourceGroup = { | |
| title: 'Existing Resource Fields', | |
| key: 'resource', | |
| weight: 50, | |
| groups: {} | |
| }; | |
| resources.forEach(function(resource) { | |
| resourceGroup.groups[resource.name] = { | |
| title: resource.title, | |
| key: resource.name, | |
| components: {} | |
| }; | |
| var groupInfo = resourceGroup.groups[resource.name]; | |
| FormioUtils.eachComponent(resource.components, function(component) { | |
| groupInfo.components[component.key] = { | |
| title: component.label || component.title || component.legend || component.key, | |
| key: resource.name + '_' + component.key, | |
| schema: component | |
| }; | |
| }); | |
| }); | |
| this.builderOptions.builder.resource = resourceGroup; | |
| this.builderReady = true; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <formio-builder *ngIf="builderReady" [form]="builderForm" [options]="builderOptions"></formio-builder> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment