Skip to content

Commit e009b9b

Browse files
committed
feat(coq-model-attribute): $attributes items value can now be object
If object given as $attributes item value, it will be used as attributes to add on element Closes #9
1 parent b9128b1 commit e009b9b

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

dist/angular-coq.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ angular.module('coq').provider('coqModelForm', function () {
208208
angular.extend(inputsDefinitions, $injector.get(module));
209209
});
210210
return {
211-
getInputAttributes: function (type) {
212-
return inputsDefinitions[type] || {};
211+
getInputAttributes: function (inputConfig) {
212+
return angular.isString(inputConfig) ? inputsDefinitions[inputConfig] || {} : inputConfig;
213213
}
214214
};
215215
}
@@ -230,9 +230,9 @@ angular.module('coq').directive('coqModelAttribute', [
230230
$log.error('coq-model-attribute need a parent element with coq-model directive');
231231
return;
232232
}
233-
var type = coqModelController.coqModel.$attributesDefinition[attrs.coqModelAttribute] || false;
234-
if (type) {
235-
element.attr(coqModelForm.getInputAttributes(type));
233+
var inputConfig = coqModelController.coqModel.$attributesDefinition[attrs.coqModelAttribute] || false;
234+
if (inputConfig) {
235+
element.attr(coqModelForm.getInputAttributes(inputConfig));
236236
element.attr('ng-model', coqModelController.coqModelName + '.' + attrs.coqModelAttribute);
237237
}
238238
}

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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@
1414

1515
app.factory('TeamsModel', function($resource, Coq) {
1616
return Coq.factory({
17-
$resource : $resource('/teams/:id'),
18-
$attributes : {
19-
id : 'number',
20-
name : 'text'
21-
}
17+
$resource : $resource('/teams/:id'),
18+
$attributes : {
19+
id : 'number',
20+
name : {
21+
type : "text",
22+
required : "required",
23+
maxlength : 10
24+
}
25+
}
2226
});
2327
});
2428

lib/directives/coq-form-services.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ angular.module('coq').provider('coqModelForm', function() {
2727
});
2828

2929
return {
30-
getInputAttributes : function(type) {
31-
return inputsDefinitions[type] || {};
30+
// Given a input config, return attributes to add to element
31+
getInputAttributes : function(inputConfig) {
32+
return angular.isString(inputConfig) ? (inputsDefinitions[inputConfig] || {}) : inputConfig;
3233
}
3334
};
3435
};

lib/directives/coq-model-attribute.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ angular.module('coq').directive('coqModelAttribute', function($compile, $log, co
1111
return;
1212
}
1313

14-
var type = coqModelController.coqModel.$attributesDefinition[attrs.coqModelAttribute] || false;
15-
if (type) {
16-
element.attr(coqModelForm.getInputAttributes(type));
14+
var inputConfig = coqModelController.coqModel.$attributesDefinition[attrs.coqModelAttribute] || false;
15+
if (inputConfig) {
16+
element.attr(coqModelForm.getInputAttributes(inputConfig));
1717
element.attr('ng-model', coqModelController.coqModelName + '.' + attrs.coqModelAttribute);
1818
}
1919
}

0 commit comments

Comments
 (0)