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

Commit c1850a0

Browse files
author
Kent C. Dodds
committed
Somehow these got lost when I submitted my PR, but they're here now. Rebased master as well
1 parent d5d6208 commit c1850a0

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ Version numbers correspond to `bower.json` version
66

77
Added `hide` property on fields. Allows devs to conditionally show fields. Also adding `hideExpression` property which is an expression that will be evaluated on the result object (using $parse) to make the api simpler to use.
88

9+
Added `template` property on fields. Allows devs to have one-liner templates. Mainly used for directives so a single template can be used with options. Also improved the id of fields that use templateUrls or templates.
10+
911
## Bug Fixes
1012

1113
## Breaking Changes

src/views/custom-field.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
app.directive('customField', function($timeout) {
2+
return {
3+
template: function(el, attrs) {
4+
return [
5+
'<div class="form-group" style="position:relative">',
6+
(attrs.hasOwnProperty('addSmile') ? ':-)' : ''),
7+
'<label for="{{id}}">',
8+
'{{options.label || "Text"}}',
9+
'{{options.required ? "*" : ""}}',
10+
'</label>',
11+
'<input type="text"',
12+
'class="form-control"',
13+
'id="{{id}}"',
14+
'placeholder="{{options.placeholder}}"',
15+
'ng-required="options.required"',
16+
'ng-disabled="options.disabled"',
17+
'ng-change="onChange(value)"',
18+
'ng-model="value">',
19+
'<span ng-show="loading" style="position:absolute;top:34px;right:10px;color:lightgray;font-size:.8em">',
20+
'Pretending to load something...',
21+
'</span>',
22+
'</div>'
23+
].join(' ');
24+
},
25+
link: function($scope, $element, $attr) {
26+
$scope.loading = false;
27+
var loadingTimeout = null;
28+
$scope.onChange = function pretendToLoadSomething(value) {
29+
$timeout.cancel(loadingTimeout);
30+
if (!value) {
31+
return;
32+
}
33+
$scope.loading = true;
34+
loadingTimeout = $timeout(function() {
35+
$scope.loading = false;
36+
}, Math.floor((Math.random() * 600) + 300));
37+
};
38+
}
39+
};
40+
});

src/views/custom-template.html

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<div class="form-group">
2+
<div>Look mah! Custom Templates!</div>
3+
<label for="{{id}}">
4+
{{options.label || 'Text'}}
5+
{{options.required ? '*' : ''}}
6+
</label>
7+
<div>{{value}}</div>
8+
<input type="text"
9+
class="form-control"
10+
id="{{id}}"
11+
placeholder="{{options.placeholder}}"
12+
ng-required="options.required"
13+
ng-disabled="options.disabled"
14+
ng-model="value">
15+
</div>

0 commit comments

Comments
 (0)