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

Commit 602ceeb

Browse files
author
Kent C. Dodds
committed
Adding documentation for the new hide property on fields
1 parent 11c4127 commit 602ceeb

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.
@@ -146,6 +151,13 @@ When constructing fields use the options below to customize each field object. Y
146151
###### Default
147152
>`undefined`
148153
154+
---
155+
##### hide (boolean)
156+
>`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.
157+
158+
###### Default
159+
>`undefined`
160+
149161
---
150162
##### disabled (boolean)
151163
>`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
@@ -142,7 +142,12 @@ app.controller('home', function($scope, $parse, $rootScope) {
142142
}, {
143143
key: 'checkThis',
144144
type: 'checkbox',
145-
label: 'Check this here'
145+
label: 'Check this here (to reveal something secret...)'
146+
}, {
147+
key: 'hiddenWhenUnchecked',
148+
type: 'text',
149+
label: 'Conditional input',
150+
hide: true
146151
}, {
147152
key:'secretCode',
148153
type: 'hidden',
@@ -159,4 +164,12 @@ app.controller('home', function($scope, $parse, $rootScope) {
159164
$scope.formOptionsStr = $scope.toPrettyJSON($scope.formOptions, 4);
160165
$scope.formFieldsError = false;
161166
$scope.formOptionsError = false;
167+
var hiddenWhenUncheckedIndex = 0;
168+
$scope.formFields.some(function(field, index) {
169+
hiddenWhenUncheckedIndex = index;
170+
return field.key === 'hiddenWhenUnchecked';
171+
});
172+
$scope.$watch('formData.checkThis', function(isChecked) {
173+
$scope.formFields[hiddenWhenUncheckedIndex].hide = !isChecked;
174+
});
162175
});

0 commit comments

Comments
 (0)