Skip to content
This repository was archived by the owner on Feb 19, 2025. It is now read-only.

Commit 2912b8f

Browse files
author
Dean Sofer
committed
Made some changes in line with comments
For some reason $compile() is throwing an error Stubbed out uiForm dependency but need help creating the directive
1 parent 04844e2 commit 2912b8f

File tree

1 file changed

+17
-36
lines changed

1 file changed

+17
-36
lines changed

modules/directives/input/input.js

+17-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
angular.module('ui.directives', ['ui.config'])
2-
.factory('InputHelper', ['$compile', '$http', '$templateCache', 'ui.config', function ($compile, $http, $templateCache, uiConfig) {
1+
angular.module('ui.directives')
2+
.directive('uiInput', ['$compile', '$http', '$templateCache', 'ui.config', function ($compile, $http, $templateCache, uiConfig) {
33

4-
uiConfig.uiinput = uiConfig.uiinput || {};
4+
uiConfig.input = uiConfig.input || {};
55

66
var idUid = ['0', '0', '0'];
77
var nameUid = ['0', '0', '0'];
@@ -42,60 +42,41 @@ angular.module('ui.directives', ['ui.config'])
4242
});
4343
}
4444

45-
var internalAttrs = ['family', 'kind', 'validation'];
46-
4745
return {
48-
restrict:'E',
46+
restrict:'EA',
4947
priority:10000,
5048
terminal:true,
51-
compile:function compile(tElement, tAttrs, transclude) {
49+
scope:true,
50+
require:'?uiForm',
51+
compile:function compile(tElement, tAttrs, transclude, uiForm) {
5252

53-
var control = {
54-
id:tAttrs.id || 'id' + nextUid(idUid)
53+
var model = tAttrs.ngModel, input = {
54+
id:tAttrs.id || 'input' + nextUid(idUid)
5555
};
5656

5757
return function (scope, element, attrs) {
5858

59-
var childScope = scope.$new();
60-
var tplFamily = tAttrs.family || uiConfig.uiinput.family;
61-
var tplKind = tAttrs.kind || uiConfig.uiinput.kind;
62-
6359
//infer a field type from template's tag name (can be one of ui-input, ui-select, ui-textarea)
64-
var targetTagName = tElement[0].tagName.substring(3).toLowerCase();
65-
66-
$http.get(targetTagName + '.' + tplFamily + '.' + tplKind + '.html', {cache:$templateCache}).success(function (response) {
60+
$http.get(scope.$eval(attrs.src), {cache:$templateCache}).success(function (response) {
6761

6862
element.html(response);
6963

70-
var inputEl = angular.element(element.find(targetTagName)[0]);
64+
var inputEl = element.find('[ng-transclude]');
7165
angular.forEach(tAttrs, function (value, key) {
72-
if (key.charAt(0) !== '$') {
73-
if (key.indexOf('input') === 0) {
74-
control[key.charAt(5).toLowerCase() + key.substr(6)] = value;
75-
} else {
76-
inputEl.attr(snake_case(key, '-'), value);
77-
}
66+
if (key.charAt(0) !== '$' && ['src','uiInput'].indexOf(key) === -1) {
67+
inputEl.attr(snake_case(key, '-'), value);
7868
}
7969
});
8070

8171
//prepare validation messages
82-
control.validation = angular.extend({}, uiConfig.uiinput.validation, scope.$eval(tAttrs.validation));
72+
input.validation = angular.extend({}, uiConfig.input.validation, scope.$eval(tAttrs.validation));
8373

8474
//expose model to a field's template
85-
childScope.$control = control;
86-
$compile(element.contents())(childScope);
87-
childScope.$field = inputEl.controller('ngModel');
75+
scope.$input = input;
76+
$compile(element.contents())(scope);
77+
scope.$field = inputEl.controller('ngModel');
8878
});
8979
};
9080
}
9181
};
92-
}])
93-
.directive('uiInput', ['InputHelper', function (InputHelper) {
94-
return InputHelper;
95-
}])
96-
.directive('uiTextarea', ['InputHelper', function (InputHelper) {
97-
return InputHelper;
98-
}])
99-
.directive('uiSelect', ['InputHelper', function (InputHelper) {
100-
return InputHelper;
10182
}]);

0 commit comments

Comments
 (0)