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

Commit 71737da

Browse files
author
Kamil Kisiela
committed
feat(helpers): ngModelAttrsTransformer
1 parent f28e342 commit 71737da

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/helpers/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,27 @@ export function ngModelAttrsManipulator(template, options, attrName, attrValue)
5353

5454
return node.innerHTML;
5555
}
56+
57+
/**
58+
* Adds ngModelAttr to the field when specified condition is true.
59+
* @param {Array} fields fields provided by formly's fieldTranform
60+
* @param {Funcion} condition with field as only parameter
61+
* @param {String} name ngModelAttr's name
62+
* @param {Object} settings ngModelAttr's settings
63+
* @return {Array} returns fields
64+
*/
65+
export function ngModelAttrsTransformer(fields, condition, name, settings) {
66+
(fields || []).forEach((field) => {
67+
if (condition(field) === true) {
68+
if (!field.ngModelAttrs) {
69+
field.ngModelAttrs = {};
70+
}
71+
72+
if (typeof field.templateOptions[name] !== 'undefined') {
73+
field.ngModelAttrs[name] = settings;
74+
}
75+
}
76+
});
77+
78+
return fields;
79+
}

0 commit comments

Comments
 (0)