Skip to content
This repository was archived by the owner on Apr 30, 2018. It is now read-only.

Commit bf785cb

Browse files
committed
Merge branch 'kentcdodds-master'
2 parents b7cbe31 + fcd636a commit bf785cb

17 files changed

+200
-88
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
Version numbers correspond to `bower.json` version
22

3+
# 0.0.11
4+
5+
## Features
6+
7+
Adding the `formlyTemplateProvider` which allows developers to set templateUrls for types. Also allows them to make custom types.
8+
9+
## Bug Fixes
10+
11+
## Breaking Changes
12+
313
# 0.0.10
414

515
## Features

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module.exports = function(grunt) {
3535
{
3636
expand: true,
3737
cwd: '<%= formlyConfig.base %>/',
38-
src: ['directives/formly*.*', 'modules/formly*.*', '!.jshintrc'],
38+
src: ['directives/formly*.*', 'modules/formly*.*', 'providers/formly*.*', '!.jshintrc'],
3939
dest: '.tmp/'
4040
}
4141
]
@@ -52,7 +52,7 @@ module.exports = function(grunt) {
5252
concat: {
5353
build: {
5454
// specifing files so that they are added in this order
55-
src: ['.tmp/modules/formly*.js', '.tmp/directives/formly*.js', '.tmp/formly*.js'],
55+
src: ['.tmp/modules/formly*.js', '.tmp/directives/formly*.js', '.tmp/providers/formly*.js', '.tmp/formly*.js'],
5656
dest: '.tmp/formly.js'
5757
}
5858
},

README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,37 @@ _Example password field_
396396
}
397397
```
398398

399+
## Other Notes
400+
401+
### Global Config
402+
403+
You can configure formly to use custom templates for specified types (your own "text" template) by injecting the `formlyTemplateProvider` in your app's `config` function. The `formlyTemplateProvider` has the following functions:
404+
405+
#### setTemplateUrl
406+
407+
Allows you to set a template
408+
409+
```javascript
410+
formlyTemplateProvider.setTemplateUrl('radio', 'views/custom-formly-radio.html');
411+
formlyTemplateProvider.setTemplateUrl('checkbox', 'views/custom-formly-checkbox.html');
412+
413+
// the same can be accomplished with
414+
415+
formlyTemplateProvider.setTemplate({
416+
radio: 'views/custom-formly-radio.html',
417+
checkbox: 'views/custom-formly-checkbox.html'
418+
});
419+
```
420+
421+
#### getTemplateUrl
422+
423+
Allows you to get the template
424+
425+
```javascript
426+
formlyTemplateProvider.setTemplateUrl('radio', 'views/custom-formly-radio.html');
427+
formlyTemplateProvider.getTemplateUrl('radio') === 'views/custom-formly-radio.html'; // true
428+
```
429+
399430
## Roadmap
400431

401432
## Release Notes

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-formly",
3-
"version": "0.0.10",
3+
"version": "0.0.11",
44
"authors": [
55
"Grant Helton <[email protected]>"
66
],

dist/formly.js

Lines changed: 35 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,8 @@ angular.module('formly.render').directive('formlyField', [
77
'$http',
88
'$compile',
99
'$templateCache',
10-
function formlyField($http, $compile, $templateCache) {
11-
var getTemplateUrl = function (type) {
12-
var templateUrl = '';
13-
switch (type) {
14-
case 'textarea':
15-
templateUrl = 'directives/formly-field-textarea.html';
16-
break;
17-
case 'radio':
18-
templateUrl = 'directives/formly-field-radio.html';
19-
break;
20-
case 'select':
21-
templateUrl = 'directives/formly-field-select.html';
22-
break;
23-
case 'number':
24-
templateUrl = 'directives/formly-field-number.html';
25-
break;
26-
case 'checkbox':
27-
templateUrl = 'directives/formly-field-checkbox.html';
28-
break;
29-
case 'password':
30-
templateUrl = 'directives/formly-field-password.html';
31-
break;
32-
case 'hidden':
33-
templateUrl = 'directives/formly-field-hidden.html';
34-
break;
35-
case 'email':
36-
templateUrl = 'directives/formly-field-email.html';
37-
break;
38-
case 'text':
39-
templateUrl = 'directives/formly-field-text.html';
40-
break;
41-
default:
42-
templateUrl = null;
43-
break;
44-
}
45-
return templateUrl;
46-
};
10+
'formlyTemplate',
11+
function formlyField($http, $compile, $templateCache, formlyTemplate) {
4712
return {
4813
restrict: 'AE',
4914
transclude: true,
@@ -58,7 +23,7 @@ angular.module('formly.render').directive('formlyField', [
5823
if (template) {
5924
setElementTemplate(template);
6025
} else {
61-
var templateUrl = $scope.options.templateUrl || getTemplateUrl($scope.options.type);
26+
var templateUrl = $scope.options.templateUrl || formlyTemplate.getTemplateUrl($scope.options.type);
6227
if (templateUrl) {
6328
$http.get(templateUrl, { cache: $templateCache }).then(function (response) {
6429
setElementTemplate(response.data);
@@ -132,6 +97,38 @@ angular.module('formly.render').directive('formlyForm', function formlyForm() {
13297
]
13398
};
13499
});
100+
'use strict';
101+
angular.module('formly.render').provider('formlyTemplate', function () {
102+
var templateMap = {
103+
textarea: 'directives/formly-field-textarea.html',
104+
radio: 'directives/formly-field-radio.html',
105+
select: 'directives/formly-field-select.html',
106+
number: 'directives/formly-field-number.html',
107+
checkbox: 'directives/formly-field-checkbox.html',
108+
password: 'directives/formly-field-password.html',
109+
hidden: 'directives/formly-field-hidden.html',
110+
email: 'directives/formly-field-email.html',
111+
text: 'directives/formly-field-text.html'
112+
};
113+
function setTemplateUrl(name, templateUrl) {
114+
if (typeof name === 'string') {
115+
templateMap[name] = templateUrl;
116+
} else {
117+
angular.forEach(name, function (templateUrl, name) {
118+
setTemplateUrl(name, templateUrl);
119+
});
120+
}
121+
}
122+
function getTemplateUrl(type) {
123+
return templateMap[type];
124+
}
125+
;
126+
this.setTemplateUrl = setTemplateUrl;
127+
this.getTemplateUrl = getTemplateUrl;
128+
this.$get = function formlyTemplate() {
129+
return this;
130+
};
131+
});
135132
angular.module('formly.render').run([
136133
'$templateCache',
137134
function ($templateCache) {

dist/formly.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)