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

Commit b57e9b6

Browse files
author
Kent C. Dodds
committed
Adding documentation for the new hide property on fields
1 parent ef4785e commit b57e9b6

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
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.10
4+
5+
## Features
6+
7+
Added `hide` property on fields. Allows devs to conditionally show fields.
8+
9+
## Bug Fixes
10+
11+
## Breaking Changes
12+
313
# 0.0.1
414

515
## Features

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Example data as it would be set in the controller
5757
label: 'Password',
5858
required: true,
5959
disabled: false, //default: false
60+
hide: true, // see watch below
6061
}
6162

6263
];
@@ -78,6 +79,10 @@ Example data as it would be set in the controller
7879
$scope.onSubmit = function() {
7980
console.log('form submitted:', $scope.formData);
8081
};
82+
83+
$scope.$watch('!formData.username', function(isBlank) {
84+
$scope.formFields[1].hide = !isBlank;
85+
});
8186
```
8287
### Creating Forms
8388
Forms can be customized with the options below.
@@ -139,6 +144,13 @@ When constructing fields use the options below to customize each field object. Y
139144
###### Default
140145
>`undefined`
141146
147+
---
148+
##### hide (boolean)
149+
>`hide` when true, the input is hidden (meant to be used with a watch). In the example above, the password field would be hidden until username has a value.
150+
151+
###### Default
152+
>`undefined`
153+
142154
---
143155
##### disabled (boolean)
144156
>`disabled` is used to add the disabled attribute to a form field.

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.9",
3+
"version": "0.0.10",
44
"authors": [
55
"Grant Helton <[email protected]>"
66
],

dist/formly.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ angular.module('formly.render').directive('formlyField', [
4949
transclude: true,
5050
scope: {
5151
optionsData: '&options',
52-
formId: '@formId',
53-
index: '@index',
52+
formId: '=formId',
53+
index: '=index',
5454
value: '=formValue'
5555
},
5656
link: function fieldLink($scope, $element, $attr) {
57-
var templateUrl = getTemplateUrl($scope.options.type);
57+
var templateUrl = $scope.options.templateUrl || getTemplateUrl($scope.options.type);
5858
if (templateUrl) {
5959
$http.get(templateUrl, { cache: $templateCache }).success(function (data) {
6060
//template data returned
@@ -69,7 +69,7 @@ angular.module('formly.render').directive('formlyField', [
6969
'$scope',
7070
function fieldController($scope) {
7171
$scope.options = $scope.optionsData();
72-
if ($scope.options.default) {
72+
if (typeof $scope.options.default !== 'undefined') {
7373
$scope.value = $scope.options.default;
7474
}
7575
// set field id to link labels and fields
@@ -86,18 +86,11 @@ angular.module('formly.render').directive('formlyForm', function formlyForm() {
8686
templateUrl: 'directives/formly-form.html',
8787
replace: true,
8888
scope: {
89-
formId: '@formId',
9089
fields: '=fields',
9190
options: '=options',
9291
result: '=result',
9392
formOnParentScope: '=name'
9493
},
95-
controller: [
96-
'$scope',
97-
'$element',
98-
function formController($scope, $element) {
99-
}
100-
],
10194
compile: function (scope, iElement, iAttrs, controller, transcludeFn) {
10295
return {
10396
post: function (scope, ele, attr, controller) {
@@ -123,6 +116,6 @@ angular.module('formly.render').run([
123116
$templateCache.put('directives/formly-field-text.html', '<div class=form-group><label for={{id}}>{{options.label || \'Text\'}} {{options.required ? \'*\' : \'\'}}</label><input class=form-control id={{id}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value></div>');
124117
$templateCache.put('directives/formly-field-textarea.html', '<div class=form-group><label for={{id}}>{{options.label || \'Text\'}} {{options.required ? \'*\' : \'\'}}</label><textarea type=text class=form-control id={{id}} rows={{options.lines}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value>\n' + '\t</textarea></div>');
125118
$templateCache.put('directives/formly-field.html', '');
126-
$templateCache.put('directives/formly-form.html', '<form class=formly role=form><formly-field ng-repeat="field in fields" options=field form-value=result[field.key||$index] class=formly-field form-id={{options.uniqueFormId}} index={{$index}}></formly-field><button type=submit ng-hide=options.hideSubmit>{{options.submitCopy || "Submit"}}</button></form>');
119+
$templateCache.put('directives/formly-form.html', '<form class=formly role=form><formly-field ng-repeat="field in fields" options=field form-value=result[field.key||$index] class=formly-field form-id=options.uniqueFormId index=$index ng-hide=field.hide></formly-field><button type=submit ng-hide=options.hideSubmit>{{options.submitCopy || "Submit"}}</button></form>');
127120
}
128121
]);

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.

dist/formly.min.map

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

src/views/home.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ app.controller('home', function($scope, $parse, $rootScope) {
132132
}, {
133133
key: 'checkThis',
134134
type: 'checkbox',
135-
label: 'Check this here'
135+
label: 'Check this here (to reveal something secret...)'
136+
}, {
137+
key: 'hiddenWhenUnchecked',
138+
type: 'text',
139+
label: 'Conditional input',
140+
hide: true
136141
}, {
137142
key:'secretCode',
138143
type: 'hidden',
@@ -149,4 +154,12 @@ app.controller('home', function($scope, $parse, $rootScope) {
149154
$scope.formOptionsStr = $scope.toPrettyJSON($scope.formOptions, 4);
150155
$scope.formFieldsError = false;
151156
$scope.formOptionsError = false;
157+
var hiddenWhenUncheckedIndex = 0;
158+
$scope.formFields.some(function(field, index) {
159+
hiddenWhenUncheckedIndex = index;
160+
return field.key === 'hiddenWhenUnchecked';
161+
});
162+
$scope.$watch('formData.checkThis', function(isChecked) {
163+
$scope.formFields[hiddenWhenUncheckedIndex].hide = !isChecked;
164+
});
152165
});

0 commit comments

Comments
 (0)