Skip to content

Commit 34f28fb

Browse files
committed
new files for input directive
1 parent 67dd753 commit 34f28fb

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<input ng-model="modelValue" class="form-control" ng-blur="updateModel(modelValue)">
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
angular.module('asfAddon').directive('updateOnBlur', [function() {
2+
return {
3+
require: 'ngModel',
4+
restrict: 'E',
5+
scope: {},
6+
templateUrl: 'src/templates/update-on-blur-directive.html',
7+
link: function(scope, element, attrs, ngModel) {
8+
9+
ngModel.$render(function() {
10+
scope.modelValue = ngModel.$viewValue();
11+
});
12+
13+
scope.updateModel = function(value) {
14+
ngModel.$setViewValue(value);
15+
};
16+
17+
}
18+
};
19+
}]);

app/templates/input/src/templates/template.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ <h2>{{form.myOwnFormOption}}</h2>
55
<!-- Create your own form options -->
66

77
<label>{{form.title}}</label>
8-
8+
<% if (directive) { %>
9+
<update-on-blur sf-field-model schema-validate="form"></update-on-blur>
10+
<% } else { %>
911
<input sf-field-model schema-validate="form" type="text" class="form-control">
12+
<% } %>
1013
<!-- sf-field-model let's the ngModel builder know that you want a ng-model that matches against the form key here -->
1114
<!-- schema-validate="form" validates the form against the schema -->
1215

0 commit comments

Comments
 (0)