UNPKG

@eform/ng-formio-builder

Version:

The Angular.js form builder component.

64 lines (60 loc) 2.51 kB
var _assign = require('lodash/assign'); module.exports = function(app) { app.config([ 'formioComponentsProvider', function(formioComponentsProvider) { formioComponentsProvider.register('custom', { icon: 'fa fa-cubes', views: [ { name: 'Display', template: 'formio/components/custom/display.html' }, { name: 'Conditional', template: 'formio/components/common/conditional.html' } ], documentation: 'http://help.form.io/userguide/#custom' }); } ]); app.controller('customComponent', [ '$scope', 'formioComponents', function( $scope, formioComponents ) { // Because of the weirdnesses of prototype inheritence, components can't update themselves, only their properties. $scope.customComponent = angular.copy($scope.component); $scope.$watch('customComponent', function(newValue) { if (newValue) { // Don't allow a type of a real type. newValue.type = (formioComponents.components.hasOwnProperty(newValue.type) ? 'custom' : newValue.type); // Ensure some key settings are set. newValue.key = newValue.key || newValue.type; newValue.protected = (newValue.hasOwnProperty('protected') ? newValue.protected : false); newValue.persistent = (newValue.hasOwnProperty('persistent') ? newValue.persistent : true); $scope.updateKey(newValue); _assign($scope.component, newValue); } }); } ]); app.run([ '$templateCache', function($templateCache) { // Create the settings markup. $templateCache.put('formio/components/custom/display.html', '<ng-form>' + '<div class="form-group">' + '<p>Custom components can be used to render special fields or widgets inside your app. For information on how to display in an app, see <a href="http://help.form.io/userguide/#custom" target="_blank">custom component documentation</a>.</p>' + '<label for="json" form-builder-tooltip="Enter the JSON for this custom element.">{{\'Custom Element JSON\' | formioTranslate}}</label>' + '<textarea ng-controller="customComponent" class="form-control" id="json" name="json" json-input ng-model="customComponent" placeholder="{}" rows="10"></textarea>' + '</div>' + '</ng-form>' ); } ]); };