Skip to content

Instantly share code, notes, and snippets.

@travist
Created June 29, 2018 19:29
Show Gist options
  • Select an option

  • Save travist/c258516cc150b253d4b69ac4196aff27 to your computer and use it in GitHub Desktop.

Select an option

Save travist/c258516cc150b253d4b69ac4196aff27 to your computer and use it in GitHub Desktop.
Angular Form Builder
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;
}
}
<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