@@ -16,7 +16,8 @@ angular.module('formly.render').directive('formlyField', [
16
16
optionsData : '&options' ,
17
17
formId : '=formId' ,
18
18
index : '=index' ,
19
- value : '=formValue'
19
+ value : '=formValue' ,
20
+ result : '=formResult'
20
21
} ,
21
22
link : function fieldLink ( $scope , $element , $attr ) {
22
23
var template = $scope . options . template ;
@@ -94,7 +95,7 @@ angular.module('formly.render').directive('formlyForm', [
94
95
function ( $scope , $element , $parse ) {
95
96
// setup watches for watchExpressions
96
97
angular . forEach ( $scope . fields , function ( field , index ) {
97
- if ( angular . isDefined ( field . watch ) ) {
98
+ if ( angular . isDefined ( field . watch ) && angular . isDefined ( field . watch . expression ) && angular . isDefined ( field . watch . listener ) ) {
98
99
var watchExpression = field . watch . expression ;
99
100
if ( angular . isFunction ( watchExpression ) ) {
100
101
// wrap the field's watch expression so we can call it with the field as the first arg as a helper
@@ -117,6 +118,9 @@ angular.module('formly.render').directive('formlyForm', [
117
118
if ( field . hideExpression ) {
118
119
field . hide = $parse ( field . hideExpression ) ( $scope . result ) ;
119
120
}
121
+ if ( field . requiredExpression ) {
122
+ field . required = $parse ( field . requiredExpression ) ( $scope . result ) ;
123
+ }
120
124
} ) ;
121
125
} , true ) ;
122
126
}
@@ -187,15 +191,15 @@ angular.module('formly.render').run([
187
191
'$templateCache' ,
188
192
function ( $templateCache ) {
189
193
'use strict' ;
190
- $templateCache . put ( 'directives/formly-field-checkbox.html' , '<div class=checkbox><label><input type=checkbox ng-required=options.required ng-disabled=options.disabled ng-model=value> {{options.label || \'Checkbox\'}} {{options.required ? \'*\' : \'\'}}</label></div>' ) ;
191
- $templateCache . put ( 'directives/formly-field-email.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Email\'}} {{options.required ? \'*\' : \'\'}}</label><input type=email class=form-control id={{id}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value></div>' ) ;
194
+ $templateCache . put ( 'directives/formly-field-checkbox.html' , '<div class=checkbox><label><input type=checkbox aria-describedby={{id}}_description ng-required=options.required ng-disabled=options.disabled ng-model=value> {{options.label || \'Checkbox\'}} {{options.required ? \'*\' : \'\'}}</label><p id={{id}}_description class=help-block ng-if=options.description>{{options.description}}</p ></div>' ) ;
195
+ $templateCache . put ( 'directives/formly-field-email.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Email\'}} {{options.required ? \'*\' : \'\'}}</label><input type=email class=form-control id={{id}} placeholder={{options.placeholder}} aria-describedby={{id}}_description ng-required=options.required ng-disabled=options.disabled ng-model=value><p id={{id}}_description class=help-block ng-if=options.description>{{options.description}}</p ></div>' ) ;
192
196
$templateCache . put ( 'directives/formly-field-hidden.html' , '<input type=hidden ng-model=value>' ) ;
193
- $templateCache . put ( 'directives/formly-field-number.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Number\'}} {{options.required ? \'*\' : \'\'}}</label><input type=number class=form-control id={{id}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled min={{options.min}} max={{options.max}} ng-minlength={{options.minlength}} ng-maxlength={{options.maxlength}} ng-model=value></div>' ) ;
194
- $templateCache . put ( 'directives/formly-field-password.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Password\'}} {{options.required ? \'*\' : \'\'}}</label><input type=password class=form-control id={{id}} ng-required=options.required ng-disabled=options.disabled ng-model=value></div>' ) ;
195
- $templateCache . put ( 'directives/formly-field-radio.html' , '<div class=radio-group><label class=control-label>{{options.label}} {{options.required ? \'*\' : \'\'}}</label><div class=radio ng-repeat="(key, option) in options.options"><label><input type=radio name={{id}} id="{{id + \'_\'+ $index}}" ng-value=option.value ng-required=options.required ng-model=$parent.value> {{option.name}}</label></div></div>' ) ;
196
- $templateCache . put ( 'directives/formly-field-select.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Select\'}} {{options.required ? \'*\' : \'\'}}</label><select class=form-control id={{id}} ng-model=value ng-required=options.required ng-disabled=options.disabled ng-init="value = options.options[options.default]" ng-options="option.name group by option.group for option in options.options"></select></div>' ) ;
197
- $templateCache . put ( 'directives/formly-field-text.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Text\'}} {{options.required ? \'*\' : \'\'}}</label><input type=text class=form-control id={{id}} placeholder={{options.placeholder}} ng-required=options.required ng-disabled=options.disabled ng-model=value></div>' ) ;
198
- $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>' ) ;
197
+ $templateCache . put ( 'directives/formly-field-number.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Number\'}} {{options.required ? \'*\' : \'\'}}</label><input type=number class=form-control id={{id}} placeholder={{options.placeholder}} aria-describedby={{id}}_description ng-required=options.required ng-disabled=options.disabled min={{options.min}} max={{options.max}} ng-minlength={{options.minlength}} ng-maxlength={{options.maxlength}} ng-model=value><p id={{id}}_description class=help-block ng-if=options.description>{{options.description}}</p ></div>' ) ;
198
+ $templateCache . put ( 'directives/formly-field-password.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Password\'}} {{options.required ? \'*\' : \'\'}}</label><input type=password class=form-control id={{id}} aria-describedby={{id}}_description ng-required=options.required ng-disabled=options.disabled ng-model=value><p id={{id}}_description class=help-block ng-if=options.description>{{options.description}}</p ></div>' ) ;
199
+ $templateCache . put ( 'directives/formly-field-radio.html' , '<div class=radio-group><label class=control-label>{{options.label}} {{options.required ? \'*\' : \'\'}}</label><div class=radio ng-repeat="(key, option) in options.options"><label><input type=radio name={{id}} id="{{id + \'_\'+ $index}}" aria-describedby={{id}}_description ng-value=option.value ng-required=options.required ng-model=$parent.value> {{option.name}}</label><p id={{id}}_description class=help-block ng-if=option.description>{{option.description}}</p ></div></div>' ) ;
200
+ $templateCache . put ( 'directives/formly-field-select.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Select\'}} {{options.required ? \'*\' : \'\'}}</label><select class=form-control id={{id}} aria-describedby={{id}}_description ng-model=value ng-required=options.required ng-disabled=options.disabled ng-init="value = options.options[options.default]" ng-options="option.value as option. name group by option.group for option in options.options"></select><p id={{id}}_description class=help-block ng-if=options.description>{{options.description}}</p ></div>' ) ;
201
+ $templateCache . put ( 'directives/formly-field-text.html' , '<div class=form-group><label for={{id}}>{{options.label || \'Text\'}} {{options.required ? \'*\' : \'\'}}</label><input type=text class=form-control id={{id}} placeholder={{options.placeholder}} aria-describedby={{id}}_description ng-required=options.required ng-disabled=options.disabled ng-model=value><p id={{id}}_description class=help-block ng-if=options.description>{{options.description}}</p ></div>' ) ;
202
+ $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}} aria-describedby={{id}}_description ng-required=options.required ng-disabled=options.disabled ng-model=value>\n' + '\t</textarea><p id={{id}}_description class=help-block ng-if=options.description>{{options.description}}</p ></div>' ) ;
199
203
$templateCache . put ( 'directives/formly-field.html' , '' ) ;
200
204
$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 class="btn btn-primary" ng-hide=options.hideSubmit>{{options.submitCopy || "Submit"}}</button></form>' ) ;
201
205
}
0 commit comments