diff --git a/.bowerrc b/.bowerrc index 1be75bff..8a3ec3e3 100644 --- a/.bowerrc +++ b/.bowerrc @@ -1,3 +1,3 @@ { - "directory" : "src/bower_components" -} \ No newline at end of file + "directory" : "ignored_bower_components" +} diff --git a/.gitignore b/.gitignore index 2e72d47f..1568214d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,8 +14,8 @@ logs results node_modules -bower_components +ignored_bower_components *.sublime-workspace # build folder .grunt -.tmp \ No newline at end of file +.tmp diff --git a/.jshintrc b/.jshintrc index 1f1e9ab8..bc589be1 100644 --- a/.jshintrc +++ b/.jshintrc @@ -2,14 +2,18 @@ // Details: https://github.com/victorporof/Sublime-JSHint#using-your-own-jshintrc-options // Example: https://github.com/jshint/jshint/blob/master/examples/.jshintrc // Documentation: http://www.jshint.com/docs/ - "browser": false, + "browser": true, "devel": true, "esnext": true, + "globals": { + "app": true, + "angular": false + }, "globalstrict": true, "quotmark": true, "smarttabs": true, "trailing": true, "undef": true, "unused": "vars", - "node": true + "node": false } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aaf8bbe..b98373ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,20 @@ Version numbers correspond to `bower.json` version + +# Latest (maybe 0.1.0) + +## Backward compatible changes: + +## Internal Changes + +- Moved all demo-only related files to a demo folder and added a symbolic link to src and bower_components so when it's deployed the src and bower_components go with it. This will also allow us to make a symlink in the test directory when it's created. +- Separated out the src folder into three sub folders: `common`, `bootstrap`, and `vanilla`. The build takes `bootstrap` and `vanilla` and builds them separately. They each build with `common`. There is also a separate file for setting up the default template mapping with their types and this is excluded for the `no-templates` build. The final output is: `formly.js`, `formly.bootstrap.js`, and `formly.vanilla.js`. Adding other styles will be very easy. It also should make it possible for us to have directive templates (funcationality for a field). +- Removed bower_components from git ignore because it's sort of insanity to have to install it every time... Especially when it's needed for the demo. Could name the symlink different... But not worth it I think... + +## Breaking changes: + +- Added no-template build that builds to `formly.js` and changed vanilla build to `formly.vanilla.js`. + + # 0.0.16 - The password field no longer uses whitespace trimming. @@ -67,4 +83,4 @@ Added `template` property on fields. Allows devs to have one-liner templates. Ma ## Bug Fixes -## Breaking Changes \ No newline at end of file +## Breaking Changes diff --git a/Gruntfile.js b/Gruntfile.js index 90be15b2..2bec2f78 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,12 +1,15 @@ 'use strict'; -module.exports = function(grunt) { +var _ = require('lodash-node'); - // Project configuration. - grunt.initConfig({ +module.exports = function(grunt) { + require('load-grunt-tasks')(grunt); + require('time-grunt')(grunt); + var config = { pkg: grunt.file.readJSON('package.json'), formlyConfig: { hostname: 'localhost', // change to 0.0.0.0 to listen on all connections base: 'src', + demo: 'demo', port: 4000, livereloadport: 35701 }, @@ -15,126 +18,22 @@ module.exports = function(grunt) { options: { hostname: '<%= formlyConfig.hostname %>', port: '<%= formlyConfig.port %>', - base: '<%= formlyConfig.base %>', + base: '<%= formlyConfig.demo %>', livereload: '<%= formlyConfig.livereloadport %>' } } }, 'gh-pages': { options: { - base: '<%= formlyConfig.base %>' + base: '<%= formlyConfig.demo %>' }, src: ['**'] }, clean: { - build: ['.tmp/**/*'], - dist: ['dist/**/*'] - }, - copy: { - vanilla: { - files: [ - { - expand: true, - cwd: '<%= formlyConfig.base %>/', - src: ['directives/formly*.*', 'modules/formly*.*', 'providers/formly*.*', '!.jshintrc'], - dest: '.tmp/' - } - ] - }, - bootstrap: { - files: [ - { - expand: true, - cwd: '<%= formlyConfig.base %>/', - src: ['directives/formly*.js', 'directives/bootstrap/formly*.html', 'modules/formly*.*', 'providers/formly*.*', '!.jshintrc'], - dest: '.tmp/' - } - ] - }, - deploy: { - files: [{ - expand: true, - cwd: '.tmp/dist', - src: ['formly*.*'], - dest: 'dist/' - }] - } - }, - concat: { - build: { - // specifing files so that they are added in this order - src: ['.tmp/modules/formly*.js', '.tmp/directives/formly*.js', '.tmp/providers/formly*.js', '.tmp/formly*.js'], - dest: '.tmp/formly.js' - } - }, - uglify: { - vanilla: { - src: '.tmp/dist/formly.js', - dest: '.tmp/dist/formly.min.js' - }, - bootstrap: { - src: '.tmp/dist/formly.bootstrap.js', - dest: '.tmp/dist/formly.bootstrap.min.js' - }, - options: { - mangle: true, - sourceMap: true - } - }, - ngtemplates: { - vanilla: { - cwd: '.tmp/', - src: [ - 'directives/formly*.html' - ], - dest: '.tmp/formly-templates.js', - options: { - module: 'formly.render', - htmlmin: { - collapseBooleanAttributes: true, - collapseWhitespace: true, - removeAttributeQuotes: true, - removeComments: true, // Only if you don't use comment directives! - removeEmptyAttributes: true, - removeRedundantAttributes: false, //removing this as it can removes properties that can be used when styling - removeScriptTypeAttributes: true, - removeStyleLinkTypeAttributes: true - } - } - }, - bootstrap: { - cwd: '.tmp/', - src: [ - 'directives/bootstrap/formly*.html' - ], - dest: '.tmp/formly-templates.js', - options: { - module: 'formly.render', - url: function(url) { - return url.replace('bootstrap/', ''); - }, - htmlmin: { - collapseBooleanAttributes: true, - collapseWhitespace: true, - removeAttributeQuotes: true, - removeComments: true, // Only if you don't use comment directives! - removeEmptyAttributes: true, - removeRedundantAttributes: false, //removing this as it can removes properties that can be used when styling - removeScriptTypeAttributes: true, - removeStyleLinkTypeAttributes: true - } - } - } + build: ['.tmp/**/*', 'dist/**/*'] }, - ngmin: { - vanilla: { - src: '.tmp/formly.js', - dest: '.tmp/dist/formly.js' - }, - bootstrap: { - src: '.tmp/formly.js', - dest: '.tmp/dist/formly.bootstrap.js' - } + jshint: { + src: ['src/**/*.js'] }, watch: { livereload: { @@ -143,20 +42,108 @@ module.exports = function(grunt) { livereload: '<%= formlyConfig.livereloadport %>' } } + }, + + copy: { + deploy: { + expand: true, + cwd: '.tmp/', + src: '**/*-built/**/*.*', + dest: 'dist/', + flatten: true, + filter: 'isFile', + } + }, + ngtemplates: {}, + concat: {}, + ngAnnotate: {}, + uglify: {} + }; + + // targets build config (because they're pretty much identical) + var targets = ['vanilla', 'bootstrap', 'no-template']; + + _.each(targets, function(target) { + var tmp = '.tmp/' + target; + var noTemplates = target === 'no-template'; + + var preBuiltDest = tmp + '-build-prep'; + var builtDest = tmp + '-built'; + + var templatesFile = preBuiltDest + '/formly-templates.js'; + var targetFilename = 'formly.' + target; + if (noTemplates) { + targetFilename = 'formly'; } + var concatFile = builtDest + '/' + targetFilename + '.js'; + var uglifyFile = builtDest + '/' + targetFilename + '.min.js'; + + var commonCopyPatterns = ['**/*.*'] + if (noTemplates) { + commonCopyPatterns.push('!**/formly-template-config.js'); + } + + config.copy[target] = { + files: [ + { + expand: true, + cwd: '<%= formlyConfig.base %>/', + src: [target + '/**/*.*'], + dest: preBuiltDest + }, + { + expand: true, + cwd: '<%= formlyConfig.base %>/common', + src: commonCopyPatterns, + dest: preBuiltDest + } + ] + }; + + config.ngtemplates[target] = { + cwd: preBuiltDest + '/' + target + '/', + src: [ + 'fields/**/*.html' + ], + dest: templatesFile, + options: { + module: 'formly.render', + htmlmin: { + collapseBooleanAttributes: true, + collapseWhitespace: true, + removeAttributeQuotes: true, + removeComments: true, + removeEmptyAttributes: true, + removeRedundantAttributes: false, + removeScriptTypeAttributes: true, + removeStyleLinkTypeAttributes: true + } + } + }; + + config.concat[target] = { + src: [preBuiltDest + '/modules/**/*.js', preBuiltDest + '/**/*.js'], + dest: concatFile + }; + + config.ngAnnotate[target] = { + src: concatFile, + dest: concatFile + }; + config.uglify[target] = { + src: concatFile, + dest: uglifyFile, + options: { + mangle: true, + sourceMap: true + } + }; }); - // Load the plugin that provides the "uglify" task. - grunt.loadNpmTasks('grunt-contrib-concat'); - grunt.loadNpmTasks('grunt-contrib-connect'); - grunt.loadNpmTasks('grunt-contrib-copy'); - grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-gh-pages'); - grunt.loadNpmTasks('grunt-angular-templates'); - grunt.loadNpmTasks('grunt-ngmin'); - grunt.loadNpmTasks('grunt-contrib-watch'); + + // Pass config to grunt + grunt.initConfig(config); grunt.registerTask('publish', [ 'gh-pages' @@ -167,29 +154,24 @@ module.exports = function(grunt) { 'watch' ]); - grunt.registerTask('build', [ - 'clean:dist', - 'build:vanilla', - 'build:bootstrap' - ]); + _.each(targets, function(target) { + grunt.registerTask('build:' + target, [ + 'copy:' + target, + 'ngtemplates:' + target, + 'concat:' + target, + 'ngAnnotate:' + target, + 'uglify:' + target + ]); + }); - grunt.registerTask('build:vanilla', [ - 'clean:build', - 'copy:vanilla', - 'ngtemplates:vanilla', - 'concat:build', - 'ngmin:vanilla', - 'uglify:vanilla', - 'copy:deploy' - ]); - grunt.registerTask('build:bootstrap', [ - 'clean:build', - 'copy:bootstrap', - 'ngtemplates:bootstrap', - 'concat:build', - 'ngmin:bootstrap', - 'uglify:bootstrap', - 'copy:deploy' - ]); -}; \ No newline at end of file + var buildTasks = _.map(targets, function(target) { + return 'build:' + target; + }); + buildTasks.unshift('clean:build'); + buildTasks.push('copy:deploy'); + + grunt.registerTask('build', buildTasks); + + grunt.registerTask('default', ['build']); +}; diff --git a/README.md b/README.md index 46e09676..b0e2d34a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,10 @@ ## Formly Formly for Angular is an AngularJS module which has directives to help customize and render JSON based forms. The directive originated from a need to allow our users to create surveys and distribute them easily. Currently we've can render the form data from JSON and assign a model to form so we can receive the submitted data. +```html +``` ### Demo : http://Nimbly.github.io/angular-formly/ @@ -21,15 +23,19 @@ See `bower.json` and `index.html` in the `master` branch for a full list / more `$ bower install angular-formly --save` - Include the javascript file in your index.html, Formly comes in the following flavors: - - Vanilla: no fancy styling, just plain html + - No templates: you provide all your custom templates using the `formlyTemplateProvider` `` + - Vanilla: no fancy styling, just plain html + + `` + - Bootstrap: bootstrap compatible forms, form-groups, etc. `` - - DIY: You can create your own templates with `formlyTemplateProvider`! Use any of the builds above and override all the templates or just the ones you need. + - DIY: Regardless of which flavor you use, you can create your own templates with `formlyTemplateProvider`. Use any of the builds above and override all the templates or just the ones you need. - Add 'formly' as a required module to your angular app, usually in `app.js`: `var app = angular.module('app', ['ng', 'ui.router', 'formly']);` diff --git a/bower.json b/bower.json index 442accd2..a2ca0bdd 100644 --- a/bower.json +++ b/bower.json @@ -25,12 +25,12 @@ "tests" ], "dependencies": { - "angular": "~1.2.10" + "angular": "~1.2.22" }, "devDependencies": { - "angular-ui-router": "#0.2.8-bowratic-tedium", - "angular-highlightjs": "~0.2.1", + "angular-ui-router": "~0.2.10", + "angular-highlightjs": "~0.3.0", "highlightjs": "~8.0.0", - "bootstrap": "~3.1.1" + "bootstrap": "~3.2.0" } } diff --git a/src/app.js b/demo/app.js similarity index 73% rename from src/app.js rename to demo/app.js index 170bc7e8..785c7b38 100644 --- a/src/app.js +++ b/demo/app.js @@ -20,6 +20,17 @@ app.config(function($stateProvider, $urlRouterProvider, $locationProvider, forml templateUrl: 'views/home.html', controller: 'home' }); + + // Normally wouldn't have to worry about this, + // but we need to specify it because we're not using a built version. + var fields = [ + 'textarea', 'radio', 'select', 'number', 'checkbox', + 'password', 'hidden', 'email', 'text' + ]; + angular.forEach(fields, function(field) { + formlyTemplateProvider.setTemplateUrl(field, 'src/bootstrap/fields/formly-field-' + field + '.html'); + }); + if (usingCustomTypeTemplates) { formlyTemplateProvider.setTemplateUrl('text', 'views/custom-field-text.html'); // or @@ -27,21 +38,8 @@ app.config(function($stateProvider, $urlRouterProvider, $locationProvider, forml radio: 'views/custom-field-radio.html', checkbox: 'views/custom-field-checkbox.html' }); - } else { - // using bootstrap cause vanilla is ugly, normally you would use the included prebuilt bootstrap file - formlyTemplateProvider.setTemplateUrl({ - textarea: 'directives/bootstrap/formly-field-textarea.html', - radio: 'directives/bootstrap/formly-field-radio.html', - select: 'directives/bootstrap/formly-field-select.html', - number: 'directives/bootstrap/formly-field-number.html', - checkbox: 'directives/bootstrap/formly-field-checkbox.html', - password: 'directives/bootstrap/formly-field-password.html', - hidden: 'directives/bootstrap/formly-field-hidden.html', - email: 'directives/bootstrap/formly-field-email.html', - text: 'directives/bootstrap/formly-field-text.html' - }); } - + formlyOptionsProvider.setOption('uniqueFormId', 'defaultUniqueId'); // or formlyOptionsProvider.setOption({ diff --git a/demo/bower_components b/demo/bower_components new file mode 120000 index 00000000..bad2eef1 --- /dev/null +++ b/demo/bower_components @@ -0,0 +1 @@ +../ignored_bower_components/ \ No newline at end of file diff --git a/src/index.html b/demo/index.html similarity index 71% rename from src/index.html rename to demo/index.html index c190bf31..9aa613f4 100644 --- a/src/index.html +++ b/demo/index.html @@ -16,8 +16,8 @@ Loading... - -
@@ -36,11 +36,13 @@ - - - - - - + + + + + + + + - \ No newline at end of file + diff --git a/src/main.css b/demo/main.css similarity index 100% rename from src/main.css rename to demo/main.css diff --git a/demo/src b/demo/src new file mode 120000 index 00000000..e057607e --- /dev/null +++ b/demo/src @@ -0,0 +1 @@ +../src/ \ No newline at end of file diff --git a/src/views/custom-field-checkbox.html b/demo/views/custom-field-checkbox.html similarity index 100% rename from src/views/custom-field-checkbox.html rename to demo/views/custom-field-checkbox.html diff --git a/src/views/custom-field-radio.html b/demo/views/custom-field-radio.html similarity index 100% rename from src/views/custom-field-radio.html rename to demo/views/custom-field-radio.html diff --git a/src/views/custom-field-text.html b/demo/views/custom-field-text.html similarity index 100% rename from src/views/custom-field-text.html rename to demo/views/custom-field-text.html diff --git a/src/views/custom-field.js b/demo/views/custom-field.js similarity index 100% rename from src/views/custom-field.js rename to demo/views/custom-field.js diff --git a/src/views/custom-template.html b/demo/views/custom-template.html similarity index 100% rename from src/views/custom-template.html rename to demo/views/custom-template.html diff --git a/src/views/home.html b/demo/views/home.html similarity index 100% rename from src/views/home.html rename to demo/views/home.html diff --git a/src/views/home.js b/demo/views/home.js similarity index 100% rename from src/views/home.js rename to demo/views/home.js diff --git a/dist/formly.bootstrap.js b/dist/formly.bootstrap.js index 341bec8d..b0022700 100644 --- a/dist/formly.bootstrap.js +++ b/dist/formly.bootstrap.js @@ -3,232 +3,269 @@ angular.module('formly.render', []); // Main Formly Module angular.module('formly', ['formly.render']); 'use strict'; -angular.module('formly.render').directive('formlyField', [ - '$http', - '$compile', - '$templateCache', - 'formlyTemplate', - function formlyField($http, $compile, $templateCache, formlyTemplate) { - return { - restrict: 'AE', - transclude: true, - scope: { - optionsData: '&options', - formId: '=formId', - index: '=index', - value: '=formValue', - result: '=formResult' - }, - link: function fieldLink($scope, $element, $attr) { - var template = $scope.options.template; - if (template) { - setElementTemplate(template); - } else { - var templateUrl = $scope.options.templateUrl || formlyTemplate.getTemplateUrl($scope.options.type); - if (templateUrl) { - $http.get(templateUrl, { cache: $templateCache }).then(function (response) { - setElementTemplate(response.data); - }, function (error) { - console.log('Formly Error: Problem loading template for ' + templateUrl, error); - }); - } else { - console.log('Formly Error: template type \'' + $scope.options.type + '\' not supported.'); - } - } - function setElementTemplate(templateData) { - $element.html(templateData); - $compile($element.contents())($scope); - } - }, - controller: [ - '$scope', - function fieldController($scope) { - $scope.options = $scope.optionsData(); - if (typeof $scope.options.default !== 'undefined') { - $scope.value = $scope.options.default; - } - var type = $scope.options.type; - if (!type && $scope.options.template) { - type = 'template'; - } else if (!type && $scope.options.templateUrl) { - type = 'templateUrl'; - } - // set field id to link labels and fields - $scope.id = $scope.formId + type + $scope.index; - } - ] - }; - } -]); +angular.module('formly.render') +.directive('formlyField', ["$http", "$compile", "$templateCache", "formlyTemplate", function formlyField($http, $compile, $templateCache, formlyTemplate) { + return { + restrict: 'AE', + transclude: true, + scope: { + optionsData: '&options', + formId: '=formId', + index: '=index', + value: '=formValue', + result: '=formResult' + }, + link: function fieldLink($scope, $element, $attr) { + var template = $scope.options.template; + if (template) { + setElementTemplate(template); + } else { + var templateUrl = $scope.options.templateUrl || formlyTemplate.getTemplateUrl($scope.options.type); + if (templateUrl) { + $http.get(templateUrl, { + cache: $templateCache + }).then(function(response) { + setElementTemplate(response.data); + }, function(error) { + console.log('Formly Error: Problem loading template for ' + templateUrl, error); + }); + } else { + console.log('Formly Error: template type \'' + $scope.options.type + '\' not supported.'); + } + } + function setElementTemplate(templateData) { + $element.html(templateData); + $compile($element.contents())($scope); + } + }, + controller: ["$scope", function fieldController($scope) { + $scope.options = $scope.optionsData(); + if (typeof $scope.options.default !== 'undefined') { + $scope.value = $scope.options.default; + } + var type = $scope.options.type; + if (!type && $scope.options.template) { + type = 'template'; + } else if (!type && $scope.options.templateUrl) { + type = 'templateUrl'; + } + + // set field id to link labels and fields + $scope.id = $scope.formId + type + $scope.index; + }] + }; +}]); + 'use strict'; -angular.module('formly.render').directive('formlyForm', [ - 'formlyOptions', - '$compile', - function formlyForm(formlyOptions, $compile) { - var templateHide = 'ng-hide="field.hide"'; - var fieldsTemplate = [ - '', - '' - ].join(' '); - return { - restrict: 'AE', - template: function (el, attr) { - var useNgIf = formlyOptions.getOptions().useNgIfToHide; - return [ - '
', - '
fields
', - '', - '
' - ].join(' '); - }, - replace: true, - scope: { - fields: '=', - options: '=?', - result: '=', - formOnParentScope: '=name' - }, - compile: function () { - return { - post: function (scope, ele, attr, controller) { - scope.options = angular.extend(formlyOptions.getOptions(), scope.options); - if (scope.options.submitButtonTemplate) { - ele.find('button').replaceWith($compile(scope.options.submitButtonTemplate)(scope)); - } - var template = fieldsTemplate; - if (scope.options.useNgIfToHide) { - template = template.replace(templateHide, 'ng-if="!field.hide"'); - } - ele.find('div').replaceWith($compile(template)(scope)); - //Post gets called after angular has created the FormController - //Now pass the FormController back up to the parent scope - scope.formOnParentScope = scope[attr.name]; - } - }; - }, - controller: [ - '$scope', - '$element', - '$parse', - function ($scope, $element, $parse) { - // setup watches for watchExpressions - angular.forEach($scope.fields, function (field, index) { - if (angular.isDefined(field.watch) && angular.isDefined(field.watch.expression) && angular.isDefined(field.watch.listener)) { - var watchExpression = field.watch.expression; - if (angular.isFunction(watchExpression)) { - // wrap the field's watch expression so we can call it with the field as the first arg as a helper - watchExpression = function () { - var args = Array.prototype.slice.call(arguments, 0); - args.unshift(field); - return field.watch.expression.apply(this, args); - }; - } - $scope.$watch(watchExpression, function () { - // wrap the field's watch listener so we can call it with the field as the first arg as a helper - var args = Array.prototype.slice.call(arguments, 0); - args.unshift(field); - return field.watch.listener.apply(this, args); - }); - } - }); - $scope.$watch('result', function (newValue) { - angular.forEach($scope.fields, function (field, index) { - if (field.hideExpression) { - field.hide = $parse(field.hideExpression)($scope.result); - } - if (field.requiredExpression) { - field.required = $parse(field.requiredExpression)($scope.result); - } - }); - }, true); - } - ] - }; - } -]); +angular.module('formly.render') +.directive('formlyForm', ["formlyOptions", "$compile", function formlyForm(formlyOptions, $compile) { + var templateHide = 'ng-hide="field.hide"'; + var fieldsTemplate = [ + '', + '' + ].join(' ') + return { + restrict: 'AE', + template: function(el, attr) { + var useNgIf = formlyOptions.getOptions().useNgIfToHide; + return [ + '
', + '
fields
', + '', + '
' + ].join(' '); + }, + replace: true, + scope: { + fields: '=', + options: '=?', + result: '=', + formOnParentScope: '=name' + }, + compile: function () { + return { + post: function (scope, ele, attr, controller) { + scope.options = angular.extend(formlyOptions.getOptions(), scope.options); + if (scope.options.submitButtonTemplate) { + ele.find('button').replaceWith($compile(scope.options.submitButtonTemplate)(scope)); + } + var template = fieldsTemplate; + if (scope.options.useNgIfToHide) { + template = template.replace(templateHide, 'ng-if="!field.hide"'); + } + ele.find('div').replaceWith($compile(template)(scope)); + //Post gets called after angular has created the FormController + //Now pass the FormController back up to the parent scope + scope.formOnParentScope = scope[attr.name]; + } + } + }, + controller: ["$scope", "$element", "$parse", function($scope, $element, $parse) { + // setup watches for watchExpressions + angular.forEach($scope.fields, function(field, index) { + if (angular.isDefined(field.watch) && + angular.isDefined(field.watch.expression) && + angular.isDefined(field.watch.listener)) { + var watchExpression = field.watch.expression; + if (angular.isFunction(watchExpression)) { + // wrap the field's watch expression so we can call it with the field as the first arg as a helper + watchExpression = function() { + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(field); + return field.watch.expression.apply(this, args); + } + } + + $scope.$watch(watchExpression, function() { + // wrap the field's watch listener so we can call it with the field as the first arg as a helper + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(field); + return field.watch.listener.apply(this, args); + }); + } + }); + $scope.$watch('result', function(newValue) { + angular.forEach($scope.fields, function(field, index) { + if (field.hideExpression) { + field.hide = $parse(field.hideExpression)($scope.result); + } + if (field.requiredExpression) { + field.required = $parse(field.requiredExpression)($scope.result); + } + }); + }, true); + }] + }; +}]); +angular.module('formly.render').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('fields/formly-field-checkbox.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-email.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-hidden.html', + "" + ); + + + $templateCache.put('fields/formly-field-number.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-password.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-radio.html', + "

{{option.description}}

" + ); + + + $templateCache.put('fields/formly-field-select.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-text.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-textarea.html', + "

{{options.description}}

" + ); + +}]); + 'use strict'; -angular.module('formly.render').provider('formlyOptions', function () { - var options = { - uniqueFormId: null, - submitCopy: 'Submit', - hideSubmit: false, - submitButtonTemplate: null, - useNgIfToHide: false - }; - function setOption(name, value) { - if (typeof name === 'string') { - options[name] = value; - } else { - angular.forEach(name, function (val, name) { - setOption(name, val); - }); - } - } - function getOptions() { - // copy to avoid third-parties manipulating the options outside of the api. - return angular.copy(options); - } - this.setOption = setOption; - this.getOptions = getOptions; - this.$get = function formlyOptions() { - return this; - }; +angular.module('formly.render') +.provider('formlyOptions', function() { + + var options = { + uniqueFormId: null, + submitCopy: "Submit", + hideSubmit: false, + submitButtonTemplate: null, + useNgIfToHide: false + }; + + function setOption(name, value) { + if (typeof name === 'string') { + options[name] = value; + } else { + angular.forEach(name, function(val, name) { + setOption(name, val); + }); + } + } + + function getOptions() { + // copy to avoid third-parties manipulating the options outside of the api. + return angular.copy(options); + } + + this.setOption = setOption; + this.getOptions = getOptions; + this.$get = function formlyOptions() { + return this; + } + }); +// This file adds the default templates to the formlyTemplateProvider. +// It is excluded from the no-templates build. 'use strict'; -angular.module('formly.render').provider('formlyTemplate', function () { - var templateMap = { - textarea: 'directives/formly-field-textarea.html', - radio: 'directives/formly-field-radio.html', - select: 'directives/formly-field-select.html', - number: 'directives/formly-field-number.html', - checkbox: 'directives/formly-field-checkbox.html', - password: 'directives/formly-field-password.html', - hidden: 'directives/formly-field-hidden.html', - email: 'directives/formly-field-email.html', - text: 'directives/formly-field-text.html' - }; - function setTemplateUrl(name, templateUrl) { - if (typeof name === 'string') { - templateMap[name] = templateUrl; - } else { - angular.forEach(name, function (templateUrl, name) { - setTemplateUrl(name, templateUrl); - }); - } - } - function getTemplateUrl(type) { - return templateMap[type]; - } - ; - this.setTemplateUrl = setTemplateUrl; - this.getTemplateUrl = getTemplateUrl; - this.$get = function formlyTemplate() { - return this; - }; -}); -angular.module('formly.render').run([ - '$templateCache', - function ($templateCache) { - 'use strict'; - $templateCache.put('directives/formly-field-checkbox.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-email.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-hidden.html', ''); - $templateCache.put('directives/formly-field-number.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-password.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-radio.html', '

{{option.description}}

'); - $templateCache.put('directives/formly-field-select.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-text.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-textarea.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field.html', ''); - $templateCache.put('directives/formly-form.html', '
'); - } -]); \ No newline at end of file +angular.module('formly.render').config(["formlyTemplateProvider", function(formlyTemplateProvider) { + var fields = [ + 'textarea', 'radio', 'select', 'number', 'checkbox', + 'password', 'hidden', 'email', 'text' + ]; + angular.forEach(fields, function(field) { + formlyTemplateProvider.setTemplateUrl(field, 'fields/formly-field-' + field + '.html'); + }); +}]); +'use strict'; +angular.module('formly.render') +.provider('formlyTemplate', function() { + + var templateMap = {}; + + function setTemplateUrl(name, templateUrl) { + if (typeof name === 'string') { + templateMap[name] = templateUrl; + } else { + angular.forEach(name, function(templateUrl, name) { + setTemplateUrl(name, templateUrl); + }); + } + } + + function getTemplateUrl(type) { + return templateMap[type]; + }; + + this.setTemplateUrl = setTemplateUrl; + this.getTemplateUrl = getTemplateUrl; + this.$get = function formlyTemplate() { + return this; + } + +}); \ No newline at end of file diff --git a/dist/formly.bootstrap.min.js b/dist/formly.bootstrap.min.js index cc07bfb0..8dab82d9 100644 --- a/dist/formly.bootstrap.min.js +++ b/dist/formly.bootstrap.min.js @@ -1,2 +1,2 @@ -angular.module("formly.render",[]),angular.module("formly",["formly.render"]),angular.module("formly.render").directive("formlyField",["$http","$compile","$templateCache","formlyTemplate",function(a,b,c,d){return{restrict:"AE",transclude:!0,scope:{optionsData:"&options",formId:"=formId",index:"=index",value:"=formValue",result:"=formResult"},link:function(e,f){function g(a){f.html(a),b(f.contents())(e)}var h=e.options.template;if(h)g(h);else{var i=e.options.templateUrl||d.getTemplateUrl(e.options.type);i?a.get(i,{cache:c}).then(function(a){g(a.data)},function(a){console.log("Formly Error: Problem loading template for "+i,a)}):console.log("Formly Error: template type '"+e.options.type+"' not supported.")}},controller:["$scope",function(a){a.options=a.optionsData(),"undefined"!=typeof a.options.default&&(a.value=a.options.default);var b=a.options.type;!b&&a.options.template?b="template":!b&&a.options.templateUrl&&(b="templateUrl"),a.id=a.formId+b+a.index}]}}]),angular.module("formly.render").directive("formlyForm",["formlyOptions","$compile",function(a,b){var c='ng-hide="field.hide"',d=['',""].join(" ");return{restrict:"AE",template:function(){a.getOptions().useNgIfToHide;return['
','
fields
','","
"].join(" ")},replace:!0,scope:{fields:"=",options:"=?",result:"=",formOnParentScope:"=name"},compile:function(){return{post:function(e,f,g){e.options=angular.extend(a.getOptions(),e.options),e.options.submitButtonTemplate&&f.find("button").replaceWith(b(e.options.submitButtonTemplate)(e));var h=d;e.options.useNgIfToHide&&(h=h.replace(c,'ng-if="!field.hide"')),f.find("div").replaceWith(b(h)(e)),e.formOnParentScope=e[g.name]}}},controller:["$scope","$element","$parse",function(a,b,c){angular.forEach(a.fields,function(b){if(angular.isDefined(b.watch)&&angular.isDefined(b.watch.expression)&&angular.isDefined(b.watch.listener)){var c=b.watch.expression;angular.isFunction(c)&&(c=function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.expression.apply(this,a)}),a.$watch(c,function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.listener.apply(this,a)})}}),a.$watch("result",function(){angular.forEach(a.fields,function(b){b.hideExpression&&(b.hide=c(b.hideExpression)(a.result)),b.requiredExpression&&(b.required=c(b.requiredExpression)(a.result))})},!0)}]}}]),angular.module("formly.render").provider("formlyOptions",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(){return angular.copy(c)}var c={uniqueFormId:null,submitCopy:"Submit",hideSubmit:!1,submitButtonTemplate:null,useNgIfToHide:!1};this.setOption=a,this.getOptions=b,this.$get=function(){return this}}),angular.module("formly.render").provider("formlyTemplate",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(a){return c[a]}var c={textarea:"directives/formly-field-textarea.html",radio:"directives/formly-field-radio.html",select:"directives/formly-field-select.html",number:"directives/formly-field-number.html",checkbox:"directives/formly-field-checkbox.html",password:"directives/formly-field-password.html",hidden:"directives/formly-field-hidden.html",email:"directives/formly-field-email.html",text:"directives/formly-field-text.html"};this.setTemplateUrl=a,this.getTemplateUrl=b,this.$get=function(){return this}}),angular.module("formly.render").run(["$templateCache",function(a){"use strict";a.put("directives/formly-field-checkbox.html","

{{options.description}}

"),a.put("directives/formly-field-email.html","

{{options.description}}

"),a.put("directives/formly-field-hidden.html",""),a.put("directives/formly-field-number.html","

{{options.description}}

"),a.put("directives/formly-field-password.html","

{{options.description}}

"),a.put("directives/formly-field-radio.html","

{{option.description}}

"),a.put("directives/formly-field-select.html","

{{options.description}}

"),a.put("directives/formly-field-text.html","

{{options.description}}

"),a.put("directives/formly-field-textarea.html","

{{options.description}}

"),a.put("directives/formly-field.html",""),a.put("directives/formly-form.html",'
')}]); +angular.module("formly.render",[]),angular.module("formly",["formly.render"]),angular.module("formly.render").directive("formlyField",["$http","$compile","$templateCache","formlyTemplate",function(a,b,c,d){return{restrict:"AE",transclude:!0,scope:{optionsData:"&options",formId:"=formId",index:"=index",value:"=formValue",result:"=formResult"},link:function(e,f){function g(a){f.html(a),b(f.contents())(e)}var h=e.options.template;if(h)g(h);else{var i=e.options.templateUrl||d.getTemplateUrl(e.options.type);i?a.get(i,{cache:c}).then(function(a){g(a.data)},function(a){console.log("Formly Error: Problem loading template for "+i,a)}):console.log("Formly Error: template type '"+e.options.type+"' not supported.")}},controller:["$scope",function(a){a.options=a.optionsData(),"undefined"!=typeof a.options.default&&(a.value=a.options.default);var b=a.options.type;!b&&a.options.template?b="template":!b&&a.options.templateUrl&&(b="templateUrl"),a.id=a.formId+b+a.index}]}}]),angular.module("formly.render").directive("formlyForm",["formlyOptions","$compile",function(a,b){var c='ng-hide="field.hide"',d=['',""].join(" ");return{restrict:"AE",template:function(){a.getOptions().useNgIfToHide;return['
','
fields
','","
"].join(" ")},replace:!0,scope:{fields:"=",options:"=?",result:"=",formOnParentScope:"=name"},compile:function(){return{post:function(e,f,g){e.options=angular.extend(a.getOptions(),e.options),e.options.submitButtonTemplate&&f.find("button").replaceWith(b(e.options.submitButtonTemplate)(e));var h=d;e.options.useNgIfToHide&&(h=h.replace(c,'ng-if="!field.hide"')),f.find("div").replaceWith(b(h)(e)),e.formOnParentScope=e[g.name]}}},controller:["$scope","$element","$parse",function(a,b,c){angular.forEach(a.fields,function(b){if(angular.isDefined(b.watch)&&angular.isDefined(b.watch.expression)&&angular.isDefined(b.watch.listener)){var c=b.watch.expression;angular.isFunction(c)&&(c=function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.expression.apply(this,a)}),a.$watch(c,function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.listener.apply(this,a)})}}),a.$watch("result",function(){angular.forEach(a.fields,function(b){b.hideExpression&&(b.hide=c(b.hideExpression)(a.result)),b.requiredExpression&&(b.required=c(b.requiredExpression)(a.result))})},!0)}]}}]),angular.module("formly.render").run(["$templateCache",function(a){"use strict";a.put("fields/formly-field-checkbox.html","

{{options.description}}

"),a.put("fields/formly-field-email.html","

{{options.description}}

"),a.put("fields/formly-field-hidden.html",""),a.put("fields/formly-field-number.html","

{{options.description}}

"),a.put("fields/formly-field-password.html","

{{options.description}}

"),a.put("fields/formly-field-radio.html","

{{option.description}}

"),a.put("fields/formly-field-select.html","

{{options.description}}

"),a.put("fields/formly-field-text.html","

{{options.description}}

"),a.put("fields/formly-field-textarea.html","

{{options.description}}

")}]),angular.module("formly.render").provider("formlyOptions",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(){return angular.copy(c)}var c={uniqueFormId:null,submitCopy:"Submit",hideSubmit:!1,submitButtonTemplate:null,useNgIfToHide:!1};this.setOption=a,this.getOptions=b,this.$get=function(){return this}}),angular.module("formly.render").config(["formlyTemplateProvider",function(a){var b=["textarea","radio","select","number","checkbox","password","hidden","email","text"];angular.forEach(b,function(b){a.setTemplateUrl(b,"fields/formly-field-"+b+".html")})}]),angular.module("formly.render").provider("formlyTemplate",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(a){return c[a]}var c={};this.setTemplateUrl=a,this.getTemplateUrl=b,this.$get=function(){return this}}); //# sourceMappingURL=formly.bootstrap.min.map \ No newline at end of file diff --git a/dist/formly.bootstrap.min.map b/dist/formly.bootstrap.min.map index e97a1e06..e87acd1d 100644 --- a/dist/formly.bootstrap.min.map +++ b/dist/formly.bootstrap.min.map @@ -1 +1 @@ -{"version":3,"file":"formly.bootstrap.min.js","sources":["formly.bootstrap.js"],"names":["angular","module","directive","$http","$compile","$templateCache","formlyTemplate","restrict","transclude","scope","optionsData","formId","index","value","result","link","$scope","$element","setElementTemplate","templateData","html","contents","template","options","templateUrl","getTemplateUrl","type","get","cache","then","response","data","error","console","log","controller","default","id","formlyOptions","templateHide","fieldsTemplate","join","getOptions","useNgIfToHide","replace","fields","formOnParentScope","compile","post","ele","attr","extend","submitButtonTemplate","find","replaceWith","name","$parse","forEach","field","isDefined","watch","expression","listener","watchExpression","isFunction","args","Array","prototype","slice","call","arguments","unshift","apply","this","$watch","hideExpression","hide","requiredExpression","required","provider","setOption","val","copy","uniqueFormId","submitCopy","hideSubmit","$get","setTemplateUrl","templateMap","textarea","radio","select","number","checkbox","password","hidden","email","text","run","put"],"mappings":"AACAA,QAAQC,OAAO,oBAEfD,QAAQC,OAAO,UAAW,kBAE1BD,QAAQC,OAAO,iBAAiBC,UAAU,eACxC,QACA,WACA,iBACA,iBACA,SAAqBC,EAAOC,EAAUC,EAAgBC,GACpD,OACEC,SAAU,KACVC,YAAY,EACZC,OACEC,YAAa,WACbC,OAAQ,UACRC,MAAO,SACPC,MAAO,aACPC,OAAQ,eAEVC,KAAM,SAAmBC,EAAQC,GAgB/B,QAASC,GAAmBC,GAC1BF,EAASG,KAAKD,GACdf,EAASa,EAASI,YAAYL,GAjBhC,GAAIM,GAAWN,EAAOO,QAAQD,QAC9B,IAAIA,EACFJ,EAAmBI,OACd,CACL,GAAIE,GAAcR,EAAOO,QAAQC,aAAelB,EAAemB,eAAeT,EAAOO,QAAQG,KACzFF,GACFrB,EAAMwB,IAAIH,GAAeI,MAAOvB,IAAkBwB,KAAK,SAAUC,GAC/DZ,EAAmBY,EAASC,OAC3B,SAAUC,GACXC,QAAQC,IAAI,8CAAgDV,EAAaQ,KAG3EC,QAAQC,IAAI,gCAAmClB,EAAOO,QAAQG,KAAO,sBAQ3ES,YACE,SACA,SAAyBnB,GACvBA,EAAO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AAO,qCACPC,OAAQ,sCACRC,OAAQ,sCACRC,SAAU,wCACVC,SAAU,wCACVC,OAAQ,sCACRC,MAAO,qCACPC,KAAM,oCAeVxB,MAAKc,eAAiBA,EACtBd,KAAKhD,eAAiBA,EACtBgD,KAAKa,KAAO,WACV,MAAOb,SAGXzE,QAAQC,OAAO,iBAAiBiG,KAC9B,iBACA,SAAU7F,GACR,YACAA,GAAe8F,IAAI,wCAAyC,8UAC5D9F,EAAe8F,IAAI,qCAAsC,qZACzD9F,EAAe8F,IAAI,sCAAuC,sCAC1D9F,EAAe8F,IAAI,sCAAuC,qgBAC1D9F,EAAe8F,IAAI,wCAAyC,uaAC5D9F,EAAe8F,IAAI,qCAAsC,+dACzD9F,EAAe8F,IAAI,sCAAuC,mfAC1D9F,EAAe8F,IAAI,oCAAqC,mZACxD9F,EAAe8F,IAAI,wCAAyC,2bAC5D9F,EAAe8F,IAAI,+BAAgC,IACnD9F,EAAe8F,IAAI,8BAA+B"} \ No newline at end of file +{"version":3,"file":"formly.bootstrap.min.js","sources":["formly.bootstrap.js"],"names":["angular","module","directive","$http","$compile","$templateCache","formlyTemplate","restrict","transclude","scope","optionsData","formId","index","value","result","link","$scope","$element","setElementTemplate","templateData","html","contents","template","options","templateUrl","getTemplateUrl","type","get","cache","then","response","data","error","console","log","controller","default","id","formlyOptions","templateHide","fieldsTemplate","join","getOptions","useNgIfToHide","replace","fields","formOnParentScope","compile","post","ele","attr","extend","submitButtonTemplate","find","replaceWith","name","$parse","forEach","field","isDefined","watch","expression","listener","watchExpression","isFunction","args","Array","prototype","slice","call","arguments","unshift","apply","this","$watch","hideExpression","hide","requiredExpression","required","run","put","provider","setOption","val","copy","uniqueFormId","submitCopy","hideSubmit","$get","config","formlyTemplateProvider","setTemplateUrl","templateMap"],"mappings":"AACAA,QAAQC,OAAO,oBAEfD,QAAQC,OAAO,UAAW,kBAE1BD,QAAQC,OAAO,iBACdC,UAAU,eAAgB,QAAS,WAAY,iBAAkB,iBAAkB,S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of file diff --git a/dist/formly.js b/dist/formly.js index 0bfba283..f96a2b66 100644 --- a/dist/formly.js +++ b/dist/formly.js @@ -3,230 +3,208 @@ angular.module('formly.render', []); // Main Formly Module angular.module('formly', ['formly.render']); 'use strict'; -angular.module('formly.render').directive('formlyField', [ - '$http', - '$compile', - '$templateCache', - 'formlyTemplate', - function formlyField($http, $compile, $templateCache, formlyTemplate) { - return { - restrict: 'AE', - transclude: true, - scope: { - optionsData: '&options', - formId: '=formId', - index: '=index', - value: '=formValue', - result: '=formResult' - }, - link: function fieldLink($scope, $element, $attr) { - var template = $scope.options.template; - if (template) { - setElementTemplate(template); - } else { - var templateUrl = $scope.options.templateUrl || formlyTemplate.getTemplateUrl($scope.options.type); - if (templateUrl) { - $http.get(templateUrl, { cache: $templateCache }).then(function (response) { - setElementTemplate(response.data); - }, function (error) { - console.log('Formly Error: Problem loading template for ' + templateUrl, error); - }); - } else { - console.log('Formly Error: template type \'' + $scope.options.type + '\' not supported.'); - } - } - function setElementTemplate(templateData) { - $element.html(templateData); - $compile($element.contents())($scope); - } - }, - controller: [ - '$scope', - function fieldController($scope) { - $scope.options = $scope.optionsData(); - if (typeof $scope.options.default !== 'undefined') { - $scope.value = $scope.options.default; - } - var type = $scope.options.type; - if (!type && $scope.options.template) { - type = 'template'; - } else if (!type && $scope.options.templateUrl) { - type = 'templateUrl'; - } - // set field id to link labels and fields - $scope.id = $scope.formId + type + $scope.index; - } - ] - }; - } -]); +angular.module('formly.render') +.directive('formlyField', ["$http", "$compile", "$templateCache", "formlyTemplate", function formlyField($http, $compile, $templateCache, formlyTemplate) { + return { + restrict: 'AE', + transclude: true, + scope: { + optionsData: '&options', + formId: '=formId', + index: '=index', + value: '=formValue', + result: '=formResult' + }, + link: function fieldLink($scope, $element, $attr) { + var template = $scope.options.template; + if (template) { + setElementTemplate(template); + } else { + var templateUrl = $scope.options.templateUrl || formlyTemplate.getTemplateUrl($scope.options.type); + if (templateUrl) { + $http.get(templateUrl, { + cache: $templateCache + }).then(function(response) { + setElementTemplate(response.data); + }, function(error) { + console.log('Formly Error: Problem loading template for ' + templateUrl, error); + }); + } else { + console.log('Formly Error: template type \'' + $scope.options.type + '\' not supported.'); + } + } + function setElementTemplate(templateData) { + $element.html(templateData); + $compile($element.contents())($scope); + } + }, + controller: ["$scope", function fieldController($scope) { + $scope.options = $scope.optionsData(); + if (typeof $scope.options.default !== 'undefined') { + $scope.value = $scope.options.default; + } + var type = $scope.options.type; + if (!type && $scope.options.template) { + type = 'template'; + } else if (!type && $scope.options.templateUrl) { + type = 'templateUrl'; + } + + // set field id to link labels and fields + $scope.id = $scope.formId + type + $scope.index; + }] + }; +}]); + 'use strict'; -angular.module('formly.render').directive('formlyForm', [ - 'formlyOptions', - '$compile', - function formlyForm(formlyOptions, $compile) { - var templateHide = 'ng-hide="field.hide"'; - var fieldsTemplate = [ - '', - '' - ].join(' '); - return { - restrict: 'AE', - template: function (el, attr) { - var useNgIf = formlyOptions.getOptions().useNgIfToHide; - return [ - '
', - '
fields
', - '', - '
' - ].join(' '); - }, - replace: true, - scope: { - fields: '=', - options: '=?', - result: '=', - formOnParentScope: '=name' - }, - compile: function () { - return { - post: function (scope, ele, attr, controller) { - scope.options = angular.extend(formlyOptions.getOptions(), scope.options); - if (scope.options.submitButtonTemplate) { - ele.find('button').replaceWith($compile(scope.options.submitButtonTemplate)(scope)); - } - var template = fieldsTemplate; - if (scope.options.useNgIfToHide) { - template = template.replace(templateHide, 'ng-if="!field.hide"'); - } - ele.find('div').replaceWith($compile(template)(scope)); - //Post gets called after angular has created the FormController - //Now pass the FormController back up to the parent scope - scope.formOnParentScope = scope[attr.name]; - } - }; - }, - controller: [ - '$scope', - '$element', - '$parse', - function ($scope, $element, $parse) { - // setup watches for watchExpressions - angular.forEach($scope.fields, function (field, index) { - if (angular.isDefined(field.watch) && angular.isDefined(field.watch.expression) && angular.isDefined(field.watch.listener)) { - var watchExpression = field.watch.expression; - if (angular.isFunction(watchExpression)) { - // wrap the field's watch expression so we can call it with the field as the first arg as a helper - watchExpression = function () { - var args = Array.prototype.slice.call(arguments, 0); - args.unshift(field); - return field.watch.expression.apply(this, args); - }; - } - $scope.$watch(watchExpression, function () { - // wrap the field's watch listener so we can call it with the field as the first arg as a helper - var args = Array.prototype.slice.call(arguments, 0); - args.unshift(field); - return field.watch.listener.apply(this, args); - }); - } - }); - $scope.$watch('result', function (newValue) { - angular.forEach($scope.fields, function (field, index) { - if (field.hideExpression) { - field.hide = $parse(field.hideExpression)($scope.result); - } - if (field.requiredExpression) { - field.required = $parse(field.requiredExpression)($scope.result); - } - }); - }, true); - } - ] - }; - } -]); +angular.module('formly.render') +.directive('formlyForm', ["formlyOptions", "$compile", function formlyForm(formlyOptions, $compile) { + var templateHide = 'ng-hide="field.hide"'; + var fieldsTemplate = [ + '', + '' + ].join(' ') + return { + restrict: 'AE', + template: function(el, attr) { + var useNgIf = formlyOptions.getOptions().useNgIfToHide; + return [ + '
', + '
fields
', + '', + '
' + ].join(' '); + }, + replace: true, + scope: { + fields: '=', + options: '=?', + result: '=', + formOnParentScope: '=name' + }, + compile: function () { + return { + post: function (scope, ele, attr, controller) { + scope.options = angular.extend(formlyOptions.getOptions(), scope.options); + if (scope.options.submitButtonTemplate) { + ele.find('button').replaceWith($compile(scope.options.submitButtonTemplate)(scope)); + } + var template = fieldsTemplate; + if (scope.options.useNgIfToHide) { + template = template.replace(templateHide, 'ng-if="!field.hide"'); + } + ele.find('div').replaceWith($compile(template)(scope)); + //Post gets called after angular has created the FormController + //Now pass the FormController back up to the parent scope + scope.formOnParentScope = scope[attr.name]; + } + } + }, + controller: ["$scope", "$element", "$parse", function($scope, $element, $parse) { + // setup watches for watchExpressions + angular.forEach($scope.fields, function(field, index) { + if (angular.isDefined(field.watch) && + angular.isDefined(field.watch.expression) && + angular.isDefined(field.watch.listener)) { + var watchExpression = field.watch.expression; + if (angular.isFunction(watchExpression)) { + // wrap the field's watch expression so we can call it with the field as the first arg as a helper + watchExpression = function() { + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(field); + return field.watch.expression.apply(this, args); + } + } + + $scope.$watch(watchExpression, function() { + // wrap the field's watch listener so we can call it with the field as the first arg as a helper + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(field); + return field.watch.listener.apply(this, args); + }); + } + }); + $scope.$watch('result', function(newValue) { + angular.forEach($scope.fields, function(field, index) { + if (field.hideExpression) { + field.hide = $parse(field.hideExpression)($scope.result); + } + if (field.requiredExpression) { + field.required = $parse(field.requiredExpression)($scope.result); + } + }); + }, true); + }] + }; +}]); + 'use strict'; -angular.module('formly.render').provider('formlyOptions', function () { - var options = { - uniqueFormId: null, - submitCopy: 'Submit', - hideSubmit: false, - submitButtonTemplate: null, - useNgIfToHide: false - }; - function setOption(name, value) { - if (typeof name === 'string') { - options[name] = value; - } else { - angular.forEach(name, function (val, name) { - setOption(name, val); - }); - } - } - function getOptions() { - // copy to avoid third-parties manipulating the options outside of the api. - return angular.copy(options); - } - this.setOption = setOption; - this.getOptions = getOptions; - this.$get = function formlyOptions() { - return this; - }; +angular.module('formly.render') +.provider('formlyOptions', function() { + + var options = { + uniqueFormId: null, + submitCopy: "Submit", + hideSubmit: false, + submitButtonTemplate: null, + useNgIfToHide: false + }; + + function setOption(name, value) { + if (typeof name === 'string') { + options[name] = value; + } else { + angular.forEach(name, function(val, name) { + setOption(name, val); + }); + } + } + + function getOptions() { + // copy to avoid third-parties manipulating the options outside of the api. + return angular.copy(options); + } + + this.setOption = setOption; + this.getOptions = getOptions; + this.$get = function formlyOptions() { + return this; + } + }); 'use strict'; -angular.module('formly.render').provider('formlyTemplate', function () { - var templateMap = { - textarea: 'directives/formly-field-textarea.html', - radio: 'directives/formly-field-radio.html', - select: 'directives/formly-field-select.html', - number: 'directives/formly-field-number.html', - checkbox: 'directives/formly-field-checkbox.html', - password: 'directives/formly-field-password.html', - hidden: 'directives/formly-field-hidden.html', - email: 'directives/formly-field-email.html', - text: 'directives/formly-field-text.html' - }; - function setTemplateUrl(name, templateUrl) { - if (typeof name === 'string') { - templateMap[name] = templateUrl; - } else { - angular.forEach(name, function (templateUrl, name) { - setTemplateUrl(name, templateUrl); - }); - } - } - function getTemplateUrl(type) { - return templateMap[type]; - } - ; - this.setTemplateUrl = setTemplateUrl; - this.getTemplateUrl = getTemplateUrl; - this.$get = function formlyTemplate() { - return this; - }; -}); -angular.module('formly.render').run([ - '$templateCache', - function ($templateCache) { - 'use strict'; - $templateCache.put('directives/formly-field-checkbox.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-email.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-hidden.html', ''); - $templateCache.put('directives/formly-field-number.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-password.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-radio.html', '

{{option.description}}

'); - $templateCache.put('directives/formly-field-select.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-text.html', '

{{options.description}}

'); - $templateCache.put('directives/formly-field-textarea.html', '

{{options.description}}

'); - } -]); \ No newline at end of file +angular.module('formly.render') +.provider('formlyTemplate', function() { + + var templateMap = {}; + + function setTemplateUrl(name, templateUrl) { + if (typeof name === 'string') { + templateMap[name] = templateUrl; + } else { + angular.forEach(name, function(templateUrl, name) { + setTemplateUrl(name, templateUrl); + }); + } + } + + function getTemplateUrl(type) { + return templateMap[type]; + }; + + this.setTemplateUrl = setTemplateUrl; + this.getTemplateUrl = getTemplateUrl; + this.$get = function formlyTemplate() { + return this; + } + +}); \ No newline at end of file diff --git a/dist/formly.min.js b/dist/formly.min.js index 10d9c4cd..d8f1305b 100644 --- a/dist/formly.min.js +++ b/dist/formly.min.js @@ -1,2 +1,2 @@ -angular.module("formly.render",[]),angular.module("formly",["formly.render"]),angular.module("formly.render").directive("formlyField",["$http","$compile","$templateCache","formlyTemplate",function(a,b,c,d){return{restrict:"AE",transclude:!0,scope:{optionsData:"&options",formId:"=formId",index:"=index",value:"=formValue",result:"=formResult"},link:function(e,f){function g(a){f.html(a),b(f.contents())(e)}var h=e.options.template;if(h)g(h);else{var i=e.options.templateUrl||d.getTemplateUrl(e.options.type);i?a.get(i,{cache:c}).then(function(a){g(a.data)},function(a){console.log("Formly Error: Problem loading template for "+i,a)}):console.log("Formly Error: template type '"+e.options.type+"' not supported.")}},controller:["$scope",function(a){a.options=a.optionsData(),"undefined"!=typeof a.options.default&&(a.value=a.options.default);var b=a.options.type;!b&&a.options.template?b="template":!b&&a.options.templateUrl&&(b="templateUrl"),a.id=a.formId+b+a.index}]}}]),angular.module("formly.render").directive("formlyForm",["formlyOptions","$compile",function(a,b){var c='ng-hide="field.hide"',d=['',""].join(" ");return{restrict:"AE",template:function(){a.getOptions().useNgIfToHide;return['
','
fields
','","
"].join(" ")},replace:!0,scope:{fields:"=",options:"=?",result:"=",formOnParentScope:"=name"},compile:function(){return{post:function(e,f,g){e.options=angular.extend(a.getOptions(),e.options),e.options.submitButtonTemplate&&f.find("button").replaceWith(b(e.options.submitButtonTemplate)(e));var h=d;e.options.useNgIfToHide&&(h=h.replace(c,'ng-if="!field.hide"')),f.find("div").replaceWith(b(h)(e)),e.formOnParentScope=e[g.name]}}},controller:["$scope","$element","$parse",function(a,b,c){angular.forEach(a.fields,function(b){if(angular.isDefined(b.watch)&&angular.isDefined(b.watch.expression)&&angular.isDefined(b.watch.listener)){var c=b.watch.expression;angular.isFunction(c)&&(c=function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.expression.apply(this,a)}),a.$watch(c,function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.listener.apply(this,a)})}}),a.$watch("result",function(){angular.forEach(a.fields,function(b){b.hideExpression&&(b.hide=c(b.hideExpression)(a.result)),b.requiredExpression&&(b.required=c(b.requiredExpression)(a.result))})},!0)}]}}]),angular.module("formly.render").provider("formlyOptions",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(){return angular.copy(c)}var c={uniqueFormId:null,submitCopy:"Submit",hideSubmit:!1,submitButtonTemplate:null,useNgIfToHide:!1};this.setOption=a,this.getOptions=b,this.$get=function(){return this}}),angular.module("formly.render").provider("formlyTemplate",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(a){return c[a]}var c={textarea:"directives/formly-field-textarea.html",radio:"directives/formly-field-radio.html",select:"directives/formly-field-select.html",number:"directives/formly-field-number.html",checkbox:"directives/formly-field-checkbox.html",password:"directives/formly-field-password.html",hidden:"directives/formly-field-hidden.html",email:"directives/formly-field-email.html",text:"directives/formly-field-text.html"};this.setTemplateUrl=a,this.getTemplateUrl=b,this.$get=function(){return this}}),angular.module("formly.render").run(["$templateCache",function(a){"use strict";a.put("directives/formly-field-checkbox.html","

{{options.description}}

"),a.put("directives/formly-field-email.html","

{{options.description}}

"),a.put("directives/formly-field-hidden.html",""),a.put("directives/formly-field-number.html","

{{options.description}}

"),a.put("directives/formly-field-password.html","

{{options.description}}

"),a.put("directives/formly-field-radio.html","

{{option.description}}

"),a.put("directives/formly-field-select.html","

{{options.description}}

"),a.put("directives/formly-field-text.html","

{{options.description}}

"),a.put("directives/formly-field-textarea.html","

{{options.description}}

")}]); +angular.module("formly.render",[]),angular.module("formly",["formly.render"]),angular.module("formly.render").directive("formlyField",["$http","$compile","$templateCache","formlyTemplate",function(a,b,c,d){return{restrict:"AE",transclude:!0,scope:{optionsData:"&options",formId:"=formId",index:"=index",value:"=formValue",result:"=formResult"},link:function(e,f){function g(a){f.html(a),b(f.contents())(e)}var h=e.options.template;if(h)g(h);else{var i=e.options.templateUrl||d.getTemplateUrl(e.options.type);i?a.get(i,{cache:c}).then(function(a){g(a.data)},function(a){console.log("Formly Error: Problem loading template for "+i,a)}):console.log("Formly Error: template type '"+e.options.type+"' not supported.")}},controller:["$scope",function(a){a.options=a.optionsData(),"undefined"!=typeof a.options.default&&(a.value=a.options.default);var b=a.options.type;!b&&a.options.template?b="template":!b&&a.options.templateUrl&&(b="templateUrl"),a.id=a.formId+b+a.index}]}}]),angular.module("formly.render").directive("formlyForm",["formlyOptions","$compile",function(a,b){var c='ng-hide="field.hide"',d=['',""].join(" ");return{restrict:"AE",template:function(){a.getOptions().useNgIfToHide;return['
','
fields
','","
"].join(" ")},replace:!0,scope:{fields:"=",options:"=?",result:"=",formOnParentScope:"=name"},compile:function(){return{post:function(e,f,g){e.options=angular.extend(a.getOptions(),e.options),e.options.submitButtonTemplate&&f.find("button").replaceWith(b(e.options.submitButtonTemplate)(e));var h=d;e.options.useNgIfToHide&&(h=h.replace(c,'ng-if="!field.hide"')),f.find("div").replaceWith(b(h)(e)),e.formOnParentScope=e[g.name]}}},controller:["$scope","$element","$parse",function(a,b,c){angular.forEach(a.fields,function(b){if(angular.isDefined(b.watch)&&angular.isDefined(b.watch.expression)&&angular.isDefined(b.watch.listener)){var c=b.watch.expression;angular.isFunction(c)&&(c=function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.expression.apply(this,a)}),a.$watch(c,function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.listener.apply(this,a)})}}),a.$watch("result",function(){angular.forEach(a.fields,function(b){b.hideExpression&&(b.hide=c(b.hideExpression)(a.result)),b.requiredExpression&&(b.required=c(b.requiredExpression)(a.result))})},!0)}]}}]),angular.module("formly.render").provider("formlyOptions",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(){return angular.copy(c)}var c={uniqueFormId:null,submitCopy:"Submit",hideSubmit:!1,submitButtonTemplate:null,useNgIfToHide:!1};this.setOption=a,this.getOptions=b,this.$get=function(){return this}}),angular.module("formly.render").provider("formlyTemplate",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(a){return c[a]}var c={};this.setTemplateUrl=a,this.getTemplateUrl=b,this.$get=function(){return this}}); //# sourceMappingURL=formly.min.map \ No newline at end of file diff --git a/dist/formly.min.map b/dist/formly.min.map index c022b6c2..53428496 100644 --- a/dist/formly.min.map +++ b/dist/formly.min.map @@ -1 +1 @@ -{"version":3,"file":"formly.min.js","sources":["formly.js"],"names":["angular","module","directive","$http","$compile","$templateCache","formlyTemplate","restrict","transclude","scope","optionsData","formId","index","value","result","link","$scope","$element","setElementTemplate","templateData","html","contents","template","options","templateUrl","getTemplateUrl","type","get","cache","then","response","data","error","console","log","controller","default","id","formlyOptions","templateHide","fieldsTemplate","join","getOptions","useNgIfToHide","replace","fields","formOnParentScope","compile","post","ele","attr","extend","submitButtonTemplate","find","replaceWith","name","$parse","forEach","field","isDefined","watch","expression","listener","watchExpression","isFunction","args","Array","prototype","slice","call","arguments","unshift","apply","this","$watch","hideExpression","hide","requiredExpression","required","provider","setOption","val","copy","uniqueFormId","submitCopy","hideSubmit","$get","setTemplateUrl","templateMap","textarea","radio","select","number","checkbox","password","hidden","email","text","run","put"],"mappings":"AACAA,QAAQC,OAAO,oBAEfD,QAAQC,OAAO,UAAW,kBAE1BD,QAAQC,OAAO,iBAAiBC,UAAU,eACxC,QACA,WACA,iBACA,iBACA,SAAqBC,EAAOC,EAAUC,EAAgBC,GACpD,OACEC,SAAU,KACVC,YAAY,EACZC,OACEC,YAAa,WACbC,OAAQ,UACRC,MAAO,SACPC,MAAO,aACPC,OAAQ,eAEVC,KAAM,SAAmBC,EAAQC,GAgB/B,QAASC,GAAmBC,GAC1BF,EAASG,KAAKD,GACdf,EAASa,EAASI,YAAYL,GAjBhC,GAAIM,GAAWN,EAAOO,QAAQD,QAC9B,IAAIA,EACFJ,EAAmBI,OACd,CACL,GAAIE,GAAcR,EAAOO,QAAQC,aAAelB,EAAemB,eAAeT,EAAOO,QAAQG,KACzFF,GACFrB,EAAMwB,IAAIH,GAAeI,MAAOvB,IAAkBwB,KAAK,SAAUC,GAC/DZ,EAAmBY,EAASC,OAC3B,SAAUC,GACXC,QAAQC,IAAI,8CAAgDV,EAAaQ,KAG3EC,QAAQC,IAAI,gCAAmClB,EAAOO,QAAQG,KAAO,sBAQ3ES,YACE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AAI8D,IACAC,SAAU,wCACVC,MAAO,qCACPC,OAAQ,sCACRC,OAAQ,sCACRC,SAAU,wCACVC,SAAU,wCACVC,OAAQ,sCACRC,MAAO,qCACPC,KAAM,oCAeVxB,MAAKc,eAAiBA,EACtBd,KAAKhD,eAAiBA,EACtBgD,KAAKa,KAAO,WACV,MAAOb,SAGXzE,QAAQC,OAAO,iBAAiBiG,KAC9B,iBACA,SAAU7F,GACR,YACAA,GAAe8F,IAAI,wCAAyC,8SAC5D9F,EAAe8F,IAAI,qCAAsC,gWACzD9F,EAAe8F,IAAI,sCAAuC,sCAC1D9F,EAAe8F,IAAI,sCAAuC,gdAC1D9F,EAAe8F,IAAI,wCAAyC,kXAC5D9F,EAAe8F,IAAI,qCAAsC,4ZACzD9F,EAAe8F,IAAI,sCAAuC,8bAC1D9F,EAAe8F,IAAI,oCAAqC,8VACxD9F,EAAe8F,IAAI,wCAAyC"} \ No newline at end of file +{"version":3,"file":"formly.min.js","sources":["formly.js"],"names":["angular","module","directive","$http","$compile","$templateCache","formlyTemplate","restrict","transclude","scope","optionsData","formId","index","value","result","link","$scope","$element","setElementTemplate","templateData","html","contents","template","options","templateUrl","getTemplateUrl","type","get","cache","then","response","data","error","console","log","controller","default","id","formlyOptions","templateHide","fieldsTemplate","join","getOptions","useNgIfToHide","replace","fields","formOnParentScope","compile","post","ele","attr","extend","submitButtonTemplate","find","replaceWith","name","$parse","forEach","field","isDefined","watch","expression","listener","watchExpression","isFunction","args","Array","prototype","slice","call","arguments","unshift","apply","this","$watch","hideExpression","hide","requiredExpression","required","provider","setOption","val","copy","uniqueFormId","submitCopy","hideSubmit","$get","setTemplateUrl","templateMap"],"mappings":"AACAA,QAAQC,OAAO,oBAEfD,QAAQC,OAAO,UAAW,kBAE1BD,QAAQC,OAAO,iBACdC,UAAU,eAAgB,QAAS,WAAY,iBAAkB,iBAAkB,SAAqBC,EAAOC,EAAUC,EAAgBC,GACzI,OACCC,SAAU,KACVC,YAAY,EACZC,OACCC,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yD,QAAQF,EAAM,SAAS0B,EAAK1B,GACnCyB,EAAUzB,EAAM0B,KAKnB,QAASvC,KAER,MAAO1C,SAAQkF,KAAK3D,GApBrB,GAAIA,IACH4D,aAAc,KACdC,WAAY,SACZC,YAAY,EACZjC,qBAAsB,KACtBT,eAAe,EAkBhB8B,MAAKO,UAAYA,EACjBP,KAAK/B,WAAaA,EAClB+B,KAAKa,KAAO,WACX,MAAOb,SAKTzE,QAAQC,OAAO,iBACd8E,SAAS,iBAAkB,WAI3B,QAASQ,GAAehC,EAAM/B,GACT,gBAAT+B,GACViC,EAAYjC,GAAQ/B,EAEpBxB,QAAQyD,QAAQF,EAAM,SAAS/B,EAAa+B,GAC3CgC,EAAehC,EAAM/B,KAKxB,QAASC,GAAeC,GACvB,MAAO8D,GAAY9D,GAbpB,GAAI8D,KAgBJf,MAAKc,eAAiBA,EACtBd,KAAKhD,eAAiBA,EACtBgD,KAAKa,KAAO,WACX,MAAOb"} \ No newline at end of file diff --git a/dist/formly.vanilla.js b/dist/formly.vanilla.js new file mode 100644 index 00000000..223fa65b --- /dev/null +++ b/dist/formly.vanilla.js @@ -0,0 +1,271 @@ +// Render module for formly to display forms +angular.module('formly.render', []); +// Main Formly Module +angular.module('formly', ['formly.render']); +'use strict'; +angular.module('formly.render') +.directive('formlyField', ["$http", "$compile", "$templateCache", "formlyTemplate", function formlyField($http, $compile, $templateCache, formlyTemplate) { + return { + restrict: 'AE', + transclude: true, + scope: { + optionsData: '&options', + formId: '=formId', + index: '=index', + value: '=formValue', + result: '=formResult' + }, + link: function fieldLink($scope, $element, $attr) { + var template = $scope.options.template; + if (template) { + setElementTemplate(template); + } else { + var templateUrl = $scope.options.templateUrl || formlyTemplate.getTemplateUrl($scope.options.type); + if (templateUrl) { + $http.get(templateUrl, { + cache: $templateCache + }).then(function(response) { + setElementTemplate(response.data); + }, function(error) { + console.log('Formly Error: Problem loading template for ' + templateUrl, error); + }); + } else { + console.log('Formly Error: template type \'' + $scope.options.type + '\' not supported.'); + } + } + function setElementTemplate(templateData) { + $element.html(templateData); + $compile($element.contents())($scope); + } + }, + controller: ["$scope", function fieldController($scope) { + $scope.options = $scope.optionsData(); + if (typeof $scope.options.default !== 'undefined') { + $scope.value = $scope.options.default; + } + var type = $scope.options.type; + if (!type && $scope.options.template) { + type = 'template'; + } else if (!type && $scope.options.templateUrl) { + type = 'templateUrl'; + } + + // set field id to link labels and fields + $scope.id = $scope.formId + type + $scope.index; + }] + }; +}]); + +'use strict'; +angular.module('formly.render') +.directive('formlyForm', ["formlyOptions", "$compile", function formlyForm(formlyOptions, $compile) { + var templateHide = 'ng-hide="field.hide"'; + var fieldsTemplate = [ + '', + '' + ].join(' ') + return { + restrict: 'AE', + template: function(el, attr) { + var useNgIf = formlyOptions.getOptions().useNgIfToHide; + return [ + '
', + '
fields
', + '', + '
' + ].join(' '); + }, + replace: true, + scope: { + fields: '=', + options: '=?', + result: '=', + formOnParentScope: '=name' + }, + compile: function () { + return { + post: function (scope, ele, attr, controller) { + scope.options = angular.extend(formlyOptions.getOptions(), scope.options); + if (scope.options.submitButtonTemplate) { + ele.find('button').replaceWith($compile(scope.options.submitButtonTemplate)(scope)); + } + var template = fieldsTemplate; + if (scope.options.useNgIfToHide) { + template = template.replace(templateHide, 'ng-if="!field.hide"'); + } + ele.find('div').replaceWith($compile(template)(scope)); + //Post gets called after angular has created the FormController + //Now pass the FormController back up to the parent scope + scope.formOnParentScope = scope[attr.name]; + } + } + }, + controller: ["$scope", "$element", "$parse", function($scope, $element, $parse) { + // setup watches for watchExpressions + angular.forEach($scope.fields, function(field, index) { + if (angular.isDefined(field.watch) && + angular.isDefined(field.watch.expression) && + angular.isDefined(field.watch.listener)) { + var watchExpression = field.watch.expression; + if (angular.isFunction(watchExpression)) { + // wrap the field's watch expression so we can call it with the field as the first arg as a helper + watchExpression = function() { + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(field); + return field.watch.expression.apply(this, args); + } + } + + $scope.$watch(watchExpression, function() { + // wrap the field's watch listener so we can call it with the field as the first arg as a helper + var args = Array.prototype.slice.call(arguments, 0); + args.unshift(field); + return field.watch.listener.apply(this, args); + }); + } + }); + $scope.$watch('result', function(newValue) { + angular.forEach($scope.fields, function(field, index) { + if (field.hideExpression) { + field.hide = $parse(field.hideExpression)($scope.result); + } + if (field.requiredExpression) { + field.required = $parse(field.requiredExpression)($scope.result); + } + }); + }, true); + }] + }; +}]); +angular.module('formly.render').run(['$templateCache', function($templateCache) { + 'use strict'; + + $templateCache.put('fields/formly-field-checkbox.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-email.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-hidden.html', + "" + ); + + + $templateCache.put('fields/formly-field-number.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-password.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-radio.html', + "

{{option.description}}

" + ); + + + $templateCache.put('fields/formly-field-select.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-text.html', + "

{{options.description}}

" + ); + + + $templateCache.put('fields/formly-field-textarea.html', + "

{{options.description}}

" + ); + +}]); + +'use strict'; +angular.module('formly.render') +.provider('formlyOptions', function() { + + var options = { + uniqueFormId: null, + submitCopy: "Submit", + hideSubmit: false, + submitButtonTemplate: null, + useNgIfToHide: false + }; + + function setOption(name, value) { + if (typeof name === 'string') { + options[name] = value; + } else { + angular.forEach(name, function(val, name) { + setOption(name, val); + }); + } + } + + function getOptions() { + // copy to avoid third-parties manipulating the options outside of the api. + return angular.copy(options); + } + + this.setOption = setOption; + this.getOptions = getOptions; + this.$get = function formlyOptions() { + return this; + } + +}); +// This file adds the default templates to the formlyTemplateProvider. +// It is excluded from the no-templates build. +'use strict'; +angular.module('formly.render').config(["formlyTemplateProvider", function(formlyTemplateProvider) { + var fields = [ + 'textarea', 'radio', 'select', 'number', 'checkbox', + 'password', 'hidden', 'email', 'text' + ]; + angular.forEach(fields, function(field) { + formlyTemplateProvider.setTemplateUrl(field, 'fields/formly-field-' + field + '.html'); + }); +}]); +'use strict'; +angular.module('formly.render') +.provider('formlyTemplate', function() { + + var templateMap = {}; + + function setTemplateUrl(name, templateUrl) { + if (typeof name === 'string') { + templateMap[name] = templateUrl; + } else { + angular.forEach(name, function(templateUrl, name) { + setTemplateUrl(name, templateUrl); + }); + } + } + + function getTemplateUrl(type) { + return templateMap[type]; + }; + + this.setTemplateUrl = setTemplateUrl; + this.getTemplateUrl = getTemplateUrl; + this.$get = function formlyTemplate() { + return this; + } + +}); \ No newline at end of file diff --git a/dist/formly.vanilla.min.js b/dist/formly.vanilla.min.js new file mode 100644 index 00000000..009ab957 --- /dev/null +++ b/dist/formly.vanilla.min.js @@ -0,0 +1,2 @@ +angular.module("formly.render",[]),angular.module("formly",["formly.render"]),angular.module("formly.render").directive("formlyField",["$http","$compile","$templateCache","formlyTemplate",function(a,b,c,d){return{restrict:"AE",transclude:!0,scope:{optionsData:"&options",formId:"=formId",index:"=index",value:"=formValue",result:"=formResult"},link:function(e,f){function g(a){f.html(a),b(f.contents())(e)}var h=e.options.template;if(h)g(h);else{var i=e.options.templateUrl||d.getTemplateUrl(e.options.type);i?a.get(i,{cache:c}).then(function(a){g(a.data)},function(a){console.log("Formly Error: Problem loading template for "+i,a)}):console.log("Formly Error: template type '"+e.options.type+"' not supported.")}},controller:["$scope",function(a){a.options=a.optionsData(),"undefined"!=typeof a.options.default&&(a.value=a.options.default);var b=a.options.type;!b&&a.options.template?b="template":!b&&a.options.templateUrl&&(b="templateUrl"),a.id=a.formId+b+a.index}]}}]),angular.module("formly.render").directive("formlyForm",["formlyOptions","$compile",function(a,b){var c='ng-hide="field.hide"',d=['',""].join(" ");return{restrict:"AE",template:function(){a.getOptions().useNgIfToHide;return['
','
fields
','","
"].join(" ")},replace:!0,scope:{fields:"=",options:"=?",result:"=",formOnParentScope:"=name"},compile:function(){return{post:function(e,f,g){e.options=angular.extend(a.getOptions(),e.options),e.options.submitButtonTemplate&&f.find("button").replaceWith(b(e.options.submitButtonTemplate)(e));var h=d;e.options.useNgIfToHide&&(h=h.replace(c,'ng-if="!field.hide"')),f.find("div").replaceWith(b(h)(e)),e.formOnParentScope=e[g.name]}}},controller:["$scope","$element","$parse",function(a,b,c){angular.forEach(a.fields,function(b){if(angular.isDefined(b.watch)&&angular.isDefined(b.watch.expression)&&angular.isDefined(b.watch.listener)){var c=b.watch.expression;angular.isFunction(c)&&(c=function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.expression.apply(this,a)}),a.$watch(c,function(){var a=Array.prototype.slice.call(arguments,0);return a.unshift(b),b.watch.listener.apply(this,a)})}}),a.$watch("result",function(){angular.forEach(a.fields,function(b){b.hideExpression&&(b.hide=c(b.hideExpression)(a.result)),b.requiredExpression&&(b.required=c(b.requiredExpression)(a.result))})},!0)}]}}]),angular.module("formly.render").run(["$templateCache",function(a){"use strict";a.put("fields/formly-field-checkbox.html","

{{options.description}}

"),a.put("fields/formly-field-email.html","

{{options.description}}

"),a.put("fields/formly-field-hidden.html",""),a.put("fields/formly-field-number.html","

{{options.description}}

"),a.put("fields/formly-field-password.html","

{{options.description}}

"),a.put("fields/formly-field-radio.html","

{{option.description}}

"),a.put("fields/formly-field-select.html","

{{options.description}}

"),a.put("fields/formly-field-text.html","

{{options.description}}

"),a.put("fields/formly-field-textarea.html","

{{options.description}}

")}]),angular.module("formly.render").provider("formlyOptions",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(){return angular.copy(c)}var c={uniqueFormId:null,submitCopy:"Submit",hideSubmit:!1,submitButtonTemplate:null,useNgIfToHide:!1};this.setOption=a,this.getOptions=b,this.$get=function(){return this}}),angular.module("formly.render").config(["formlyTemplateProvider",function(a){var b=["textarea","radio","select","number","checkbox","password","hidden","email","text"];angular.forEach(b,function(b){a.setTemplateUrl(b,"fields/formly-field-"+b+".html")})}]),angular.module("formly.render").provider("formlyTemplate",function(){function a(b,d){"string"==typeof b?c[b]=d:angular.forEach(b,function(b,c){a(c,b)})}function b(a){return c[a]}var c={};this.setTemplateUrl=a,this.getTemplateUrl=b,this.$get=function(){return this}}); +//# sourceMappingURL=formly.vanilla.min.map \ No newline at end of file diff --git a/dist/formly.vanilla.min.map b/dist/formly.vanilla.min.map new file mode 100644 index 00000000..5aa14903 --- /dev/null +++ b/dist/formly.vanilla.min.map @@ -0,0 +1 @@ +{"version":3,"file":"formly.vanilla.min.js","sources":["formly.vanilla.js"],"names":["angular","module","directive","$http","$compile","$templateCache","formlyTemplate","restrict","transclude","scope","optionsData","formId","index","value","result","link","$scope","$element","setElementTemplate","templateData","html","contents","template","options","templateUrl","getTemplateUrl","type","get","cache","then","response","data","error","console","log","controller","default","id","formlyOptions","templateHide","fieldsTemplate","join","getOptions","useNgIfToHide","replace","fields","formOnParentScope","compile","post","ele","attr","extend","submitButtonTemplate","find","replaceWith","name","$parse","forEach","field","isDefined","watch","expression","listener","watchExpression","isFunction","args","Array","prototype","slice","call","arguments","unshift","apply","this","$watch","hideExpression","hide","requiredExpression","required","run","put","provider","setOption","val","copy","uniqueFormId","submitCopy","hideSubmit","$get","config","formlyTemplateProvider","setTemplateUrl","templateMap"],"mappings":"AACAA,QAAQC,OAAO,oBAEfD,QAAQC,OAAO,UAAW,kBAE1BD,QAAQC,OAAO,iBACdC,UAAU,eAAgB,QAAS,WAAY,iBAAkB,iBAAkB,SAAqBC,EAAOC,EAAUC,EAAgBC,GACzI,OACCC,SAAU,KACVC,YAAY,EACZC,OACCC,YAAa,WACbC,OAAQ,UACRC,MAAO,SACPC,MAAO,aACPC,OAAQ,eAETC,KAAM,SAAmBC,EAAQC,GAkBhC,QAASC,GAAmBC,GAC3BF,EAASG,KAAKD,GACdf,EAASa,EAASI,YAAYL,GAnB/B,GAAIM,GAAWN,EAAOO,QAAQD,QAC9B,IAAIA,EACHJ,EAAmBI,OACb,CACN,GAAIE,GAAcR,EAAOO,QAAQC,aAAelB,EAAemB,eAAeT,EAAO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C,GACJ,gBAAT0C,GACVhC,EAAQgC,GAAQ1C,EAEhBb,QAAQyD,QAAQF,EAAM,SAAS4B,EAAK5B,GACnC2B,EAAU3B,EAAM4B,KAKnB,QAASzC,KAER,MAAO1C,SAAQoF,KAAK7D,GApBrB,GAAIA,IACH8D,aAAc,KACdC,WAAY,SACZC,YAAY,EACZnC,qBAAsB,KACtBT,eAAe,EAkBhB8B,MAAKS,UAAYA,EACjBT,KAAK/B,WAAaA,EAClB+B,KAAKe,KAAO,WACX,MAAOf,SAOTzE,QAAQC,OAAO,iBAAiBwF,QAAQ,yBAA0B,SAASC,GAC1E,GAAI7C,IACH,WAAY,QAAS,SAAU,SAAU,WACzC,WAAY,SAAU,QAAS,OAEhC7C,SAAQyD,QAAQZ,EAAQ,SAASa,GAChCgC,EAAuBC,eAAejC,EAAO,uBAAyBA,EAAQ,cAIhF1D,QAAQC,OAAO,iBACdgF,SAAS,iBAAkB,WAI3B,QAASU,GAAepC,EAAM/B,GACT,gBAAT+B,GACVqC,EAAYrC,GAAQ/B,EAEpBxB,QAAQyD,QAAQF,EAAM,SAAS/B,EAAa+B,GAC3CoC,EAAepC,EAAM/B,KAKxB,QAASC,GAAeC,GACvB,MAAOkE,GAAYlE,GAbpB,GAAIkE,KAgBJnB,MAAKkB,eAAiBA,EACtBlB,KAAKhD,eAAiBA,EACtBgD,KAAKe,KAAO,WACX,MAAOf"} \ No newline at end of file diff --git a/formly.sublime-project b/formly.sublime-project index 758830b5..63b03114 100644 --- a/formly.sublime-project +++ b/formly.sublime-project @@ -4,25 +4,12 @@ { "name":"Formly", "follow_symlinks": true, - "path": "./src/", - "folder_exclude_patterns": [ - "bower_components" - ] - }, - { - "name": "Settings", - "follow_symlinks": true, "path": ".", "folder_exclude_patterns": [ "node_modules", - "src", - ".grunt" + ".grunt", + ".tmp" ] - }, - { - "name": "Bower", - "follow_symlinks": true, - "path": "src/bower_components", } ] } diff --git a/package.json b/package.json index a4ddd142..cbcd7af3 100644 --- a/package.json +++ b/package.json @@ -16,19 +16,24 @@ ], "description": "AngularJS directive which takes JSON representing a form and renders to HTML", "devDependencies": { - "grunt-gh-pages": "~0.9.0", "bower": "1.2.7", + "connect-livereload": "~0.4.0", "grunt": "~0.4.1", + "grunt-angular-templates": "~0.5.1", "grunt-bower-task": "~0.3.4", "grunt-cli": "~0.1.11", - "grunt-contrib-connect": "~0.6.0", + "grunt-contrib-clean": "~0.5.0", "grunt-contrib-concat": "~0.3.0", - "grunt-angular-templates": "~0.5.1", - "grunt-ngmin": "0.0.3", + "grunt-contrib-connect": "~0.6.0", "grunt-contrib-copy": "~0.5.0", - "grunt-contrib-clean": "~0.5.0", + "grunt-contrib-jshint": "^0.10.0", "grunt-contrib-uglify": "~0.3.2", "grunt-contrib-watch": "~0.6.1", - "connect-livereload": "~0.4.0" + "grunt-gh-pages": "~0.9.0", + "grunt-ng-annotate": "^0.3.2", + "grunt-ngmin": "0.0.3", + "load-grunt-tasks": "^0.6.0", + "lodash-node": "^2.4.1", + "time-grunt": "^0.4.0" } } diff --git a/src/.jshintrc b/src/.jshintrc deleted file mode 100644 index bc589be1..00000000 --- a/src/.jshintrc +++ /dev/null @@ -1,19 +0,0 @@ -{ - // Details: https://github.com/victorporof/Sublime-JSHint#using-your-own-jshintrc-options - // Example: https://github.com/jshint/jshint/blob/master/examples/.jshintrc - // Documentation: http://www.jshint.com/docs/ - "browser": true, - "devel": true, - "esnext": true, - "globals": { - "app": true, - "angular": false - }, - "globalstrict": true, - "quotmark": true, - "smarttabs": true, - "trailing": true, - "undef": true, - "unused": "vars", - "node": false -} \ No newline at end of file diff --git a/src/directives/bootstrap/formly-field-checkbox.html b/src/bootstrap/fields/formly-field-checkbox.html similarity index 100% rename from src/directives/bootstrap/formly-field-checkbox.html rename to src/bootstrap/fields/formly-field-checkbox.html diff --git a/src/directives/bootstrap/formly-field-email.html b/src/bootstrap/fields/formly-field-email.html similarity index 100% rename from src/directives/bootstrap/formly-field-email.html rename to src/bootstrap/fields/formly-field-email.html diff --git a/src/directives/bootstrap/formly-field-hidden.html b/src/bootstrap/fields/formly-field-hidden.html similarity index 100% rename from src/directives/bootstrap/formly-field-hidden.html rename to src/bootstrap/fields/formly-field-hidden.html diff --git a/src/directives/bootstrap/formly-field-number.html b/src/bootstrap/fields/formly-field-number.html similarity index 100% rename from src/directives/bootstrap/formly-field-number.html rename to src/bootstrap/fields/formly-field-number.html diff --git a/src/directives/bootstrap/formly-field-password.html b/src/bootstrap/fields/formly-field-password.html similarity index 100% rename from src/directives/bootstrap/formly-field-password.html rename to src/bootstrap/fields/formly-field-password.html diff --git a/src/directives/bootstrap/formly-field-radio.html b/src/bootstrap/fields/formly-field-radio.html similarity index 100% rename from src/directives/bootstrap/formly-field-radio.html rename to src/bootstrap/fields/formly-field-radio.html diff --git a/src/directives/bootstrap/formly-field-select.html b/src/bootstrap/fields/formly-field-select.html similarity index 100% rename from src/directives/bootstrap/formly-field-select.html rename to src/bootstrap/fields/formly-field-select.html diff --git a/src/directives/bootstrap/formly-field-text.html b/src/bootstrap/fields/formly-field-text.html similarity index 100% rename from src/directives/bootstrap/formly-field-text.html rename to src/bootstrap/fields/formly-field-text.html diff --git a/src/directives/bootstrap/formly-field-textarea.html b/src/bootstrap/fields/formly-field-textarea.html similarity index 100% rename from src/directives/bootstrap/formly-field-textarea.html rename to src/bootstrap/fields/formly-field-textarea.html diff --git a/src/directives/formly-field.js b/src/common/directives/formly-field.js similarity index 100% rename from src/directives/formly-field.js rename to src/common/directives/formly-field.js diff --git a/src/directives/formly-form.js b/src/common/directives/formly-form.js similarity index 100% rename from src/directives/formly-form.js rename to src/common/directives/formly-form.js diff --git a/src/modules/formly-render.js b/src/common/modules/formly-render.js similarity index 100% rename from src/modules/formly-render.js rename to src/common/modules/formly-render.js diff --git a/src/modules/formly.js b/src/common/modules/formly.js similarity index 100% rename from src/modules/formly.js rename to src/common/modules/formly.js diff --git a/src/providers/formly-options.js b/src/common/providers/formly-options.js similarity index 100% rename from src/providers/formly-options.js rename to src/common/providers/formly-options.js diff --git a/src/common/providers/formly-template-config.js b/src/common/providers/formly-template-config.js new file mode 100644 index 00000000..c8189331 --- /dev/null +++ b/src/common/providers/formly-template-config.js @@ -0,0 +1,12 @@ +// This file adds the default templates to the formlyTemplateProvider. +// It is excluded from the no-templates build. +'use strict'; +angular.module('formly.render').config(function(formlyTemplateProvider) { + var fields = [ + 'textarea', 'radio', 'select', 'number', 'checkbox', + 'password', 'hidden', 'email', 'text' + ]; + angular.forEach(fields, function(field) { + formlyTemplateProvider.setTemplateUrl(field, 'fields/formly-field-' + field + '.html'); + }); +}); \ No newline at end of file diff --git a/src/providers/formly-template.js b/src/common/providers/formly-template.js similarity index 53% rename from src/providers/formly-template.js rename to src/common/providers/formly-template.js index 583c3ac7..8117bc48 100644 --- a/src/providers/formly-template.js +++ b/src/common/providers/formly-template.js @@ -2,17 +2,7 @@ angular.module('formly.render') .provider('formlyTemplate', function() { - var templateMap = { - textarea: 'directives/formly-field-textarea.html', - radio: 'directives/formly-field-radio.html', - select: 'directives/formly-field-select.html', - number: 'directives/formly-field-number.html', - checkbox: 'directives/formly-field-checkbox.html', - password: 'directives/formly-field-password.html', - hidden: 'directives/formly-field-hidden.html', - email: 'directives/formly-field-email.html', - text: 'directives/formly-field-text.html' - }; + var templateMap = {}; function setTemplateUrl(name, templateUrl) { if (typeof name === 'string') { diff --git a/src/directives/bootstrap/formly-field.html b/src/directives/bootstrap/formly-field.html deleted file mode 100644 index e69de29b..00000000 diff --git a/src/directives/bootstrap/formly-form.html b/src/directives/bootstrap/formly-form.html deleted file mode 100644 index 1ac355f3..00000000 --- a/src/directives/bootstrap/formly-form.html +++ /dev/null @@ -1,15 +0,0 @@ -
- - - -
\ No newline at end of file diff --git a/src/directives/formly-field-checkbox.html b/src/vanilla/fields/formly-field-checkbox.html similarity index 100% rename from src/directives/formly-field-checkbox.html rename to src/vanilla/fields/formly-field-checkbox.html diff --git a/src/directives/formly-field-email.html b/src/vanilla/fields/formly-field-email.html similarity index 100% rename from src/directives/formly-field-email.html rename to src/vanilla/fields/formly-field-email.html diff --git a/src/directives/formly-field-hidden.html b/src/vanilla/fields/formly-field-hidden.html similarity index 100% rename from src/directives/formly-field-hidden.html rename to src/vanilla/fields/formly-field-hidden.html diff --git a/src/directives/formly-field-number.html b/src/vanilla/fields/formly-field-number.html similarity index 100% rename from src/directives/formly-field-number.html rename to src/vanilla/fields/formly-field-number.html diff --git a/src/directives/formly-field-password.html b/src/vanilla/fields/formly-field-password.html similarity index 100% rename from src/directives/formly-field-password.html rename to src/vanilla/fields/formly-field-password.html diff --git a/src/directives/formly-field-radio.html b/src/vanilla/fields/formly-field-radio.html similarity index 100% rename from src/directives/formly-field-radio.html rename to src/vanilla/fields/formly-field-radio.html diff --git a/src/directives/formly-field-select.html b/src/vanilla/fields/formly-field-select.html similarity index 100% rename from src/directives/formly-field-select.html rename to src/vanilla/fields/formly-field-select.html diff --git a/src/directives/formly-field-text.html b/src/vanilla/fields/formly-field-text.html similarity index 100% rename from src/directives/formly-field-text.html rename to src/vanilla/fields/formly-field-text.html diff --git a/src/directives/formly-field-textarea.html b/src/vanilla/fields/formly-field-textarea.html similarity index 100% rename from src/directives/formly-field-textarea.html rename to src/vanilla/fields/formly-field-textarea.html