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

Commit 5368a1e

Browse files
committed
testing current 0.0.12 build
1 parent 66499d7 commit 5368a1e

File tree

3 files changed

+72
-37
lines changed

3 files changed

+72
-37
lines changed

dist/formly.js

Lines changed: 70 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -60,41 +60,76 @@ angular.module('formly.render').directive('formlyField', [
6060
}
6161
]);
6262
'use strict';
63-
angular.module('formly.render').directive('formlyForm', function formlyForm() {
64-
return {
65-
restrict: 'AE',
66-
templateUrl: 'directives/formly-form.html',
67-
replace: true,
68-
scope: {
69-
fields: '=fields',
70-
options: '=options',
71-
result: '=result',
72-
formOnParentScope: '=name'
73-
},
74-
compile: function (scope, iElement, iAttrs, controller, transcludeFn) {
75-
return {
76-
post: function (scope, ele, attr, controller) {
77-
//Post gets called after angular has created the FormController
78-
//Now pass the FormController back up to the parent scope
79-
scope.formOnParentScope = scope[attr.name];
80-
}
81-
};
82-
},
83-
controller: [
84-
'$scope',
85-
'$element',
86-
'$parse',
87-
function ($scope, $element, $parse) {
88-
$scope.$watch('result', function (newValue) {
89-
angular.forEach($scope.fields, function (field, index) {
90-
if (field.hideExpression) {
91-
var getter = $parse(field.hideExpression);
92-
field.hide = getter($scope.result);
63+
angular.module('formly.render').directive('formlyForm', [
64+
'formlyOptions',
65+
'$compile',
66+
function formlyForm(formlyOptions, $compile) {
67+
return {
68+
restrict: 'AE',
69+
templateUrl: 'directives/formly-form.html',
70+
replace: true,
71+
scope: {
72+
fields: '=',
73+
options: '=?',
74+
result: '=',
75+
formOnParentScope: '=name'
76+
},
77+
compile: function (scope, iElement, iAttrs, controller, transcludeFn) {
78+
return {
79+
post: function (scope, ele, attr, controller) {
80+
scope.options = angular.extend(formlyOptions.getOptions(), scope.options);
81+
if (scope.options.submitButtonTemplate) {
82+
ele.find('button').replaceWith($compile(scope.options.submitButtonTemplate)(scope));
9383
}
94-
});
95-
}, true);
96-
}
97-
]
84+
//Post gets called after angular has created the FormController
85+
//Now pass the FormController back up to the parent scope
86+
scope.formOnParentScope = scope[attr.name];
87+
}
88+
};
89+
},
90+
controller: [
91+
'$scope',
92+
'$element',
93+
'$parse',
94+
function ($scope, $element, $parse) {
95+
$scope.$watch('result', function (newValue) {
96+
angular.forEach($scope.fields, function (field, index) {
97+
if (field.hideExpression) {
98+
var getter = $parse(field.hideExpression);
99+
field.hide = getter($scope.result);
100+
}
101+
});
102+
}, true);
103+
}
104+
]
105+
};
106+
}
107+
]);
108+
'use strict';
109+
angular.module('formly.render').provider('formlyOptions', function () {
110+
var options = {
111+
uniqueFormId: null,
112+
submitCopy: 'Submit',
113+
hideSubmit: false,
114+
submitButtonTemplate: null
115+
};
116+
function setOption(name, value) {
117+
if (typeof name === 'string') {
118+
options[name] = value;
119+
} else {
120+
angular.forEach(name, function (val, name) {
121+
setOption(name, val);
122+
});
123+
}
124+
}
125+
function getOptions() {
126+
// copy to avoid third-parties manipulating the options outside of the api.
127+
return angular.copy(options);
128+
}
129+
this.setOption = setOption;
130+
this.getOptions = getOptions;
131+
this.$get = function formlyOptions() {
132+
return this;
98133
};
99134
});
100135
'use strict';
@@ -143,6 +178,6 @@ angular.module('formly.render').run([
143178
$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>');
144179
$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>');
145180
$templateCache.put('directives/formly-field.html', '');
146-
$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>');
181+
$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>');
147182
}
148183
]);

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.

0 commit comments

Comments
 (0)