Skip to content

Instantly share code, notes, and snippets.

@travist
Last active May 11, 2017 01:30
Show Gist options
  • Save travist/31e2babd43ad3e5b995f96e5737b85d2 to your computer and use it in GitHub Desktop.
Save travist/31e2babd43ad3e5b995f96e5737b85d2 to your computer and use it in GitHub Desktop.
Providing default form components to Form.io Form Builder
(function() {
'use strict';
angular
.module('formioApp')
.config(routeConfig);
/** @ngInject */
function routeConfig(
$stateProvider,
$urlRouterProvider,
$injector,
AppConfig,
FormioResourceProvider,
FormioFormsProvider,
FormioFormBuilderProvider,
FormIndexController
) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'views/main.html',
controller: FormIndexController
})
.state('users', {
abstract: true,
url: '/users',
templateUrl: 'views/users.html'
});
// Register all of the resources.
angular.forEach(AppConfig.resources, function(resource, name) {
FormioResourceProvider.register(name, resource.form, $injector.get(resource.resource + 'Provider'));
});
FormioFormsProvider.register('userform', AppConfig.appUrl, {});
FormioFormBuilderProvider.register('', AppConfig.appUrl, {
controllers: {
form: {
create: ['$scope', function($scope) {
// Default elements in the form.
$scope.form.components = [
{
type: 'textfield',
input: true,
inputType: 'text',
key: 'firstName',
label: 'First Name'
},
{
type: 'textfield',
input: true,
inputType: 'text',
key: 'lastName',
label: 'Last Name'
},
{
type: 'button',
action: 'submit',
theme: 'primary',
label: 'Submit',
key: 'submit'
}
];
}]
}
}
});
// Register the form routes.
$urlRouterProvider.otherwise('/');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment