├── .editorconfig ├── .gitignore ├── .travis.yml ├── Gruntfile.coffee ├── LICENSE ├── README.md ├── components └── default-components.coffee ├── dist ├── angular-form-builder-components.js ├── angular-form-builder-components.min.js ├── angular-form-builder.css ├── angular-form-builder.js └── angular-form-builder.min.js ├── example ├── demo.coffee ├── demo.js ├── popoverTemplate.html ├── site.css ├── site.scss └── template.html ├── index.html ├── package.json ├── src ├── angular-form-builder.scss ├── controller.coffee ├── directive.coffee ├── drag.coffee ├── module.coffee └── provider.coffee └── test ├── karma.config.coffee └── specs ├── controllerSpec.coffee ├── directiveSpec.coffee └── providerSpec.coffee /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 4 space indentation 12 | [*.{coffee,html}] 13 | indent_style = space 14 | indent_size = 4 15 | 16 | # 2 space indentation 17 | [*.{yml,json}] 18 | indent_style = space 19 | indent_size = 2 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X noise 2 | .DS_Store 3 | 4 | # PyCharm 5 | .idea 6 | 7 | # node 8 | node_modules 9 | package-lock.json 10 | 11 | # compass 12 | .sass-cache 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - 8.9.4 4 | 5 | install: 6 | - export DISPLAY=:99.0 7 | - sh -e /etc/init.d/xvfb start 8 | - npm install -g grunt-cli 9 | - npm install 10 | 11 | script: 12 | - npm test 13 | -------------------------------------------------------------------------------- /Gruntfile.coffee: -------------------------------------------------------------------------------- 1 | module.exports = (grunt) -> 2 | grunt.config.init 3 | compass: 4 | example: 5 | options: 6 | sassDir: 'example' 7 | cssDir: 'example' 8 | outputStyle: 'compressed' 9 | src: 10 | options: 11 | sassDir: 'src' 12 | cssDir: 'dist' 13 | outputStyle: 'compressed' 14 | 15 | coffee: 16 | source: 17 | files: 18 | 'dist/angular-form-builder.js': ['src/*.coffee'] 19 | components: 20 | files: 21 | 'dist/angular-form-builder-components.js': ['components/*.coffee'] 22 | demo: 23 | files: 24 | 'example/demo.js': 'example/demo.coffee' 25 | 26 | uglify: 27 | build: 28 | files: 29 | 'dist/angular-form-builder.min.js': 'dist/angular-form-builder.js' 30 | 'dist/angular-form-builder-components.min.js': 'dist/angular-form-builder-components.js' 31 | 32 | watch: 33 | compass: 34 | files: ['example/*.scss', 'src/*.scss'] 35 | tasks: ['compass'] 36 | options: 37 | spawn: no 38 | coffee: 39 | files: ['src/*.coffee', 'components/*.coffee', 'example/*.coffee'] 40 | tasks: ['coffee'] 41 | options: 42 | spawn: no 43 | 44 | connect: 45 | server: 46 | options: 47 | protocol: 'http' 48 | hostname: '*' 49 | port: 8000 50 | base: '.' 51 | 52 | karma: 53 | test: 54 | configFile: 'test/karma.config.coffee' 55 | 56 | # ----------------------------------- 57 | # register task 58 | # ----------------------------------- 59 | grunt.registerTask 'dev', [ 60 | 'compass' 61 | 'coffee' 62 | 'connect' 63 | 'watch' 64 | ] 65 | grunt.registerTask 'build', [ 66 | 'compass' 67 | 'coffee' 68 | 'uglify' 69 | ] 70 | 71 | # ----------------------------------- 72 | # Plugins 73 | # ----------------------------------- 74 | grunt.loadNpmTasks 'grunt-contrib-compass' 75 | grunt.loadNpmTasks 'grunt-contrib-coffee' 76 | grunt.loadNpmTasks 'grunt-contrib-watch' 77 | grunt.loadNpmTasks 'grunt-contrib-connect' 78 | grunt.loadNpmTasks 'grunt-karma' 79 | grunt.loadNpmTasks 'grunt-contrib-uglify' -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Kelp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # angular-form-builder [![Build Status](https://secure.travis-ci.org/kelp404/angular-form-builder.png?branch=master)](http://travis-ci.org/kelp404/angular-form-builder) [![devDependency Status](https://david-dm.org/kelp404/angular-form-builder/dev-status.png?branch=master)](https://david-dm.org/kelp404/angular-form-builder#info=devDependencies&view=table) 2 | 3 | [MIT License](http://www.opensource.org/licenses/mit-license.php) 4 | 5 | 6 | This is an AngularJS form builder written in [CoffeeScript](http://coffeescript.org). 7 | 8 | 9 | 10 | 11 | ## Frameworks 12 | 1. [AngularJS](http://angularjs.org/) 1.2.32 13 | 2. [jQuery](http://jquery.com/) 3.3.1 14 | 3. [Bootstrap 3](http://getbootstrap.com/) 15 | 4. [angular-validator](https://github.com/kelp404/angular-validator) 16 | 17 | 18 | 19 | 20 | ## $builder 21 | ```coffee 22 | # just $builder 23 | angular.module 'yourApp', ['builder'] 24 | 25 | # include $builder and default components 26 | angular.module 'yourApp', ['builder', 'builder.components'] 27 | ``` 28 | 29 | 30 | #### components 31 | ```coffee 32 | ### 33 | All components. 34 | ### 35 | $builder.components = 36 | componentName{string}: component{object} 37 | ``` 38 | 39 | 40 | #### groups 41 | ```coffee 42 | ### 43 | All groups of components. 44 | ### 45 | $builder.groups = [componentGroup{string}] 46 | ``` 47 | 48 | 49 | #### registerComponent 50 | ```coffee 51 | # .config 52 | $builderProvider.registerComponent = (name, component={}) -> 53 | ### 54 | Register the component for form-builder. 55 | @param name: The component name. 56 | @param component: The component object. 57 | group: {string} The component group. 58 | label: {string} The label of the input. 59 | description: {string} The description of the input. 60 | placeholder: {string} The placeholder of the input. 61 | editable: {bool} Is the form object editable? 62 | required: {bool} Is the form object required? 63 | validation: {string} angular-validator. "/regex/" or "[rule1, rule2]". (default is '/.*/') 64 | validationOptions: {array} [{rule: angular-validator, label: 'option label'}] the options for the validation. (default is []) 65 | options: {array} The input options. 66 | arrayToText: {bool} checkbox could use this to convert input (default is no) 67 | template: {string} html template 68 | templateUrl: {string} The url of the template. 69 | popoverTemplate: {string} html template 70 | popoverTemplateUrl: {string} The url of the popover template. 71 | ### 72 | # .run 73 | $builder.registerComponent = (name, component={}) -> 74 | ``` 75 | 76 | **component.template** 77 | ```html 78 |
79 | 80 |
81 | 82 |

{{description}}

83 |
84 |
85 | ``` 86 | 87 | **component.popoverTemplate** 88 | ```html 89 |
90 |
91 | 92 | 93 |
94 |
95 | 96 | 97 |
98 |
99 | 100 | 101 |
102 |
103 | 106 |
107 |
108 | 109 | 110 |
111 |
112 |
113 | 114 | 115 | 116 |
117 |
118 | ``` 119 | 120 | 121 | #### forms 122 | ```coffee 123 | ### 124 | builder mode: `fb-builder` you could drag and drop to build the form. 125 | form mode: `fb-form` this is the form for end-user to input value. 126 | Default is {default: []} 127 | ### 128 | $builder.forms = 129 | formName{string}: formObjects{array} 130 | ``` 131 | 132 | 133 | #### insertFormObject 134 | ```coffee 135 | $builder.insertFormObject = (name, index, formObject={}) => 136 | ### 137 | Insert the form object into the form at {index}. 138 | @param name: The form name. 139 | @param index: The form object index. 140 | @param form: The form object. 141 | id: The form object id. 142 | component: {string} The component name 143 | editable: {bool} Is the form object editable? (default is yes) 144 | label: {string} The form object label. 145 | description: {string} The form object description. 146 | placeholder: {string} The form object placeholder. 147 | options: {array} The form object options. 148 | required: {bool} Is the form object required? (default is no) 149 | validation: {string} angular-validator. "/regex/" or "[rule1, rule2]". 150 | [index]: {int} The form object index. It will be generated by $builder. 151 | @return: The form object. 152 | ### 153 | ``` 154 | 155 | #### addFormObject 156 | ```coffee 157 | $builder.addFormObject = (name, formObject={}) => 158 | ### 159 | Insert the form object into the form at last. 160 | reference $builder.insertFormObject() 161 | ### 162 | ``` 163 | 164 | #### removeFormObject 165 | ```coffee 166 | $builder.removeFormObject = (name, index) => 167 | ### 168 | Remove the form object by the index. 169 | @param name: {string} The form name. 170 | @param index: {int} The form object index. 171 | ### 172 | ``` 173 | 174 | 175 | 176 | 177 | ## builder.directive 178 | #### fb-components 179 | ```coffee 180 | a = angular.module 'builder.directive', ['builder.provider', 'builder.controller', 'builder.drag', 'validator'] 181 | fbComponents = -> 182 | ### 183 | You could use `fb-components` to render the components view. 184 | ### 185 | restrict: 'A' 186 | template: 187 | """ 188 | 193 |
194 |
196 |
197 | """ 198 | controller: 'fbComponentsController' 199 | a.directive 'fbComponents', fbComponents 200 | ``` 201 | 202 | ```html 203 |
204 | ``` 205 | 206 | 207 | #### fb-builder 208 | ```coffee 209 | a = angular.module 'builder.directive', ['builder.provider', 'builder.controller', 'builder.drag', 'validator'] 210 | fbBuilder = ($injector) -> 211 | ### 212 | You could use `fb-builder="formName"` to render the builder view. 213 | ### 214 | restrict: 'A' 215 | template: 216 | """ 217 |
218 |
220 |
221 | """ 222 | link: (scope, element, attrs) -> 223 | fbBuilder.$inject = ['$injector'] 224 | a.directive 'fbBuilder', fbBuilder 225 | ``` 226 | 227 | ```html 228 |
229 | ``` 230 | 231 | 232 | #### fb-form 233 | ```coffee 234 | a = angular.module 'builder.directive', ['builder.provider', 'builder.controller', 'builder.drag', 'validator'] 235 | fbForm = ($injector) -> 236 | ### 237 | You could use `fb-form="formName"` to render the form view for end-users. 238 | ### 239 | restrict: 'A' 240 | require: 'ngModel' # form data (end-user input value) 241 | scope: 242 | # input model for scops in ng-repeat 243 | input: '=ngModel' 244 | template: 245 | """ 246 |
247 |
248 | """ 249 | controller: 'fbFormController' 250 | link: (scope, element, attrs) -> 251 | fbForm.$inject = ['$injector'] 252 | a.directive 'fbForm', fbForm 253 | ``` 254 | 255 | ```html 256 |
257 |
258 |
259 |
260 | 261 |
262 |
263 |
264 | ``` 265 | 266 | 267 | 268 | 269 | ## builder.components 270 | > There are some default components at this module. This module is not required. 271 | + textInput 272 | + textArea 273 | + checkbox 274 | + radio 275 | + select 276 | 277 | 278 | 279 | 280 | ## Unit Test 281 | ```bash 282 | $ npm test 283 | ``` 284 | 285 | 286 | 287 | 288 | ## Development 289 | ```bash 290 | # install node modules 291 | $ npm install 292 | # install bower components 293 | $ bower install 294 | ``` 295 | ```bash 296 | # run the local server and the file watcher to compile CoffeeScript 297 | $ grunt dev 298 | # compile coffee script and minify 299 | $ grunt build 300 | ``` 301 | -------------------------------------------------------------------------------- /components/default-components.coffee: -------------------------------------------------------------------------------- 1 | angular.module 'builder.components', ['builder', 'validator.rules'] 2 | 3 | .config ['$builderProvider', ($builderProvider) -> 4 | # ---------------------------------------- 5 | # text input 6 | # ---------------------------------------- 7 | $builderProvider.registerComponent 'textInput', 8 | group: 'Default' 9 | label: 'Text Input' 10 | description: 'description' 11 | placeholder: 'placeholder' 12 | required: no 13 | validationOptions: [ 14 | {label: 'none', rule: '/.*/'} 15 | {label: 'number', rule: '[number]'} 16 | {label: 'email', rule: '[email]'} 17 | {label: 'url', rule: '[url]'} 18 | ] 19 | template: 20 | """ 21 |
22 | 23 |
24 | 25 |

{{description}}

26 |
27 |
28 | """ 29 | popoverTemplate: 30 | """ 31 |
32 |
33 | 34 | 35 |
36 |
37 | 38 | 39 |
40 |
41 | 42 | 43 |
44 |
45 | 48 |
49 |
50 | 51 | 52 |
53 | 54 |
55 |
56 | 57 | 58 | 59 |
60 |
61 | """ 62 | 63 | # ---------------------------------------- 64 | # Text area 65 | # ---------------------------------------- 66 | $builderProvider.registerComponent 'textArea', 67 | group: 'Default' 68 | label: 'Text Area' 69 | description: 'description' 70 | placeholder: 'placeholder' 71 | required: no 72 | template: 73 | """ 74 |
75 | 76 |
77 |