Skip to content

Commit e889e78

Browse files
committed
finally fixed by changing API on coq-model-attribute for now
Thanks to @CrshOverride for advices Closes #7
1 parent 66eb3d8 commit e889e78

File tree

6 files changed

+64
-59
lines changed

6 files changed

+64
-59
lines changed

dist/angular-coq.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ angular.module('coq').directive('coqModelAttribute', [
275275
'coqModelForm',
276276
function ($compile, $log, coqModelForm) {
277277
return {
278-
priority: 101,
278+
priority: 999,
279279
require: '?^coqModel',
280280
restrict: 'A',
281281
link: function (scope, element, attrs, coqModelController) {
@@ -286,7 +286,6 @@ angular.module('coq').directive('coqModelAttribute', [
286286
var inputConfig = coqModelController.coqModel.$attributesDefinition[attrs.coqModelAttribute] || false;
287287
if (inputConfig) {
288288
element.attr(coqModelForm.getInputAttributes(inputConfig));
289-
element.attr('ng-model', coqModelController.coqModelName + '.' + attrs.coqModelAttribute);
290289
}
291290
}
292291
};
@@ -313,34 +312,37 @@ angular.module('coq').directive('coqModel', [
313312
'$compile',
314313
function ($compile) {
315314
return {
316-
terminal: true,
315+
priority: 1000,
317316
controller: 'coqModelController',
318317
restrict: 'A',
319-
link: {
320-
pre: function (scope, element, attrs, coqModelController) {
321-
coqModelController.init(attrs);
322-
if (element[0].tagName === 'FORM' && !$(element).find('input[coq-model-attribute]').length) {
323-
var paragraph, input, paragraphs = [];
324-
angular.forEach(coqModelController.coqModel.$attributesDefinition, function (_, name) {
325-
paragraph = document.createElement('p');
326-
input = document.createElement('input');
327-
angular.element(input).attr('coq-model-attribute', name);
328-
angular.element(paragraph).append(input);
329-
paragraphs.push(paragraph);
330-
});
331-
if (coqModelController.insertMode === 'replace') {
332-
element.empty();
333-
element.append(paragraphs);
334-
} else {
335-
element[coqModelController.insertMode](paragraphs);
318+
compile: function () {
319+
return {
320+
pre: function (scope, element, attrs, coqModelController) {
321+
coqModelController.init(attrs);
322+
},
323+
post: function (scope, element, attrs, coqModelController) {
324+
if (element[0].tagName === 'FORM' && !$(element).find('input[coq-model-attribute]').length) {
325+
var paragraph, input, paragraphs = [];
326+
angular.forEach(coqModelController.coqModel.$attributesDefinition, function (_, name) {
327+
paragraph = document.createElement('p');
328+
input = document.createElement('input');
329+
angular.element(input).attr('coq-model-attribute', name);
330+
angular.element(input).attr('ng-model', coqModelController.coqModelName + '.' + name);
331+
angular.element(paragraph).append(input);
332+
paragraphs.push(paragraph);
333+
});
334+
if (coqModelController.insertMode === 'replace') {
335+
element.empty();
336+
element.append(paragraphs);
337+
} else {
338+
element[coqModelController.insertMode](paragraphs);
339+
}
340+
$compile(element.contents())(scope);
341+
$compile(element.contents())(scope);
342+
paragraphs = null;
336343
}
337-
$compile(element.contents())(scope);
338-
paragraphs = null;
339344
}
340-
},
341-
post: function (scope, iElement) {
342-
$compile(iElement.contents())(scope);
343-
}
345+
};
344346
}
345347
};
346348
}

dist/angular-coq.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.

examples/directives.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
app.controller('myController', function($scope, TeamsModel) {
3030
$scope.team = new TeamsModel({ name : 'test', id : 1 });
31-
$scope.team2 = new TeamsModel();
31+
$scope.team2 = new TeamsModel({ name : 'charly' });
3232
});
3333
</script>
3434
</head>
@@ -38,18 +38,20 @@ <h2>Edit a team</h2>
3838

3939
<form coq-model="team" ng-model="myForm"></form>
4040

41-
{{ team | json }}
41+
team : {{ team | json }}
4242

4343
<hr>
4444

4545
<h2>Create a team</h2>
4646

4747
<form coq-model="team2" ng-model="myForm2" ng-submit="team2.save()">
48-
<p>Name : <input coq-model-attribute="name"></p>
48+
<p>Name : <input coq-model-attribute="name" ng-model="team2.name"></p>
4949

5050
<input type="submit">
5151
<a ng-click="team2.save()" href>click me</a>
5252
</form>
53+
54+
team2 : {{ team2 | json }}
5355
</div>
5456
</body>
5557
</html>

lib/directives/coq-model-attribute.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
angular.module('coq').directive('coqModelAttribute', function($compile, $log, coqModelForm) {
44
return {
5-
priority : 101,
5+
priority : 999,
66
require : '?^coqModel',
77
restrict : 'A',
88
link: function(scope, element, attrs, coqModelController) {
@@ -14,8 +14,8 @@ angular.module('coq').directive('coqModelAttribute', function($compile, $log, co
1414
var inputConfig = coqModelController.coqModel.$attributesDefinition[attrs.coqModelAttribute] || false;
1515
if (inputConfig) {
1616
element.attr(coqModelForm.getInputAttributes(inputConfig));
17-
element.attr('ng-model', coqModelController.coqModelName + '.' + attrs.coqModelAttribute);
1817
}
18+
1919
}
2020
};
2121

lib/directives/coq-model.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,37 @@ angular.module('coq').controller('coqModelController', function($scope, $parse)
1111

1212
angular.module('coq').directive('coqModel', function($compile) {
1313
return {
14-
terminal : true,
14+
priority : 1000,
1515
controller : 'coqModelController',
1616
restrict : 'A',
17-
link : {
18-
pre : function(scope, element, attrs, coqModelController) {
19-
20-
coqModelController.init(attrs);
21-
22-
if (element[0].tagName === 'FORM' && !$(element).find('input[coq-model-attribute]').length) {
23-
var paragraph, input, paragraphs = [];
24-
angular.forEach(coqModelController.coqModel.$attributesDefinition, function(_, name) {
25-
paragraph = document.createElement('p');
26-
input = document.createElement('input');
27-
angular.element(input).attr('coq-model-attribute', name);
28-
angular.element(paragraph).append(input);
29-
paragraphs.push(paragraph);
30-
});
31-
if (coqModelController.insertMode === 'replace') {
32-
element.empty();
33-
element.append(paragraphs);
34-
} else {
35-
element[coqModelController.insertMode](paragraphs);
17+
compile : function() {
18+
return {
19+
pre : function(scope, element, attrs, coqModelController) {
20+
coqModelController.init(attrs);
21+
},
22+
post : function(scope, element, attrs, coqModelController) {
23+
if (element[0].tagName === 'FORM' && !$(element).find('input[coq-model-attribute]').length) {
24+
var paragraph, input, paragraphs = [];
25+
angular.forEach(coqModelController.coqModel.$attributesDefinition, function(_, name) {
26+
paragraph = document.createElement('p');
27+
input = document.createElement('input');
28+
angular.element(input).attr('coq-model-attribute', name);
29+
angular.element(input).attr('ng-model', coqModelController.coqModelName + '.' + name);
30+
angular.element(paragraph).append(input);
31+
paragraphs.push(paragraph);
32+
});
33+
if (coqModelController.insertMode === 'replace') {
34+
element.empty();
35+
element.append(paragraphs);
36+
} else {
37+
element[coqModelController.insertMode](paragraphs);
38+
}
39+
$compile(element.contents())(scope);
40+
$compile(element.contents())(scope);
41+
paragraphs = null;
3642
}
37-
$compile(element.contents())(scope);
38-
paragraphs = null;
3943
}
40-
},
41-
post : function (scope, iElement) {
42-
$compile(iElement.contents())(scope);
43-
}
44+
};
4445
}
4546
};
4647

test/spec/directives/coq-model-attribute.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('coq-model-attribute directive', function() {
4545

4646
var input;
4747

48-
element = $compile('<form coq-model="user"><input coq-model-attribute="name"></form>')(scope);
48+
element = $compile('<form coq-model="user"><input coq-model-attribute="name" ng-model="user.name"></form>')(scope);
4949

5050
input = element.find('input');
5151

0 commit comments

Comments
 (0)