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

Commit 3ed5982

Browse files
author
Kent C. Dodds
committed
Adding requiredExpression. Fixes #66
1 parent 2d8e76e commit 3ed5982

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
Version numbers correspond to `bower.json` version
2+
# Latest
3+
4+
- Now providing the `result` to each field template authors have the power to associate other values of the result set with the template
5+
- Adding `requiredExpression` to field options and assinging the field's `required` property based on its evaluation. Works very much like `hideExpression`
6+
27
# 0.0.14
38

49
Botched a publish with npm, so 0.0.13 became 0.0.14, just needed to update the changelog.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ When constructing fields use the options below to customize each field object. Y
158158
###### Default
159159
>`undefined`
160160
161+
---
162+
##### requiredExpression (expression string)
163+
>`requiredExpression` is used to conditionally require the input. Evaluates on the `result` and uses the `required` property on the field.
164+
165+
###### Default
166+
>`undefined`
167+
161168
---
162169
##### hideExpression (expression string)
163170
>`hideExpression` is used to conditionally show the input. Evaluates on the `result` and uses the `hide` property on the field.

src/directives/formly-form.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ angular.module('formly.render')
5353
if (field.hideExpression) {
5454
field.hide = $parse(field.hideExpression)($scope.result);
5555
}
56+
if (field.requiredExpression) {
57+
field.required = $parse(field.requiredExpression)($scope.result);
58+
}
5659
});
5760
}, true);
5861
}

src/views/home.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,16 @@ app.controller('home', function($scope, $parse, formlyOptions, $window, usingCus
6161
label: 'Last Name',
6262
placeholder: 'Doe'
6363
}, {
64+
key: 'emailRequired',
65+
type: 'checkbox',
66+
label: 'Email required',
67+
description: 'Do you really want us to have your email?'
68+
}, {
6469
key: 'email',
6570
type: 'email',
6671
placeholder: '[email protected]',
67-
description: 'We won\'t spam you'
72+
description: 'We won\'t spam you',
73+
requiredExpression: 'emailRequired'
6874
}, {
6975
key: 'about',
7076
type: 'textarea',

0 commit comments

Comments
 (0)