Skip to content

Commit ee9ba51

Browse files
committed
Convert from string to correct types in plugInHelper
1 parent eedfc93 commit ee9ba51

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

bower.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@
1818
"dist/forms-angular.js"
1919
],
2020
"dependencies": {
21-
"angular": "~1.3",
22-
"angular-sanitize": "~1.3",
23-
"angular-messages": "~1.3",
21+
"angular": "1.3.16",
22+
"angular-sanitize": "1.3.16",
23+
"angular-messages": "1.3.16",
2424
"angular-ui-bootstrap-bower": ">=0.8.0",
2525
"underscore": "1.8.2",
2626
"ngInfiniteScroll": "^1.2",
2727
"angular-elastic": "~2"
2828
},
2929
"devDependencies": {
30-
"angular-mocks": "~1.3",
30+
"angular-mocks": "1.3.16",
3131
"bootstrap-3-1-1": "git://github.com/twbs/bootstrap.git#v3.1.1",
3232
"bootstrap-2-3-2": "git://github.com/twbs/bootstrap.git#v2.3.2"
3333
},
@@ -42,8 +42,5 @@
4242
"test",
4343
"Gruntfile.js",
4444
"package.json"
45-
],
46-
"resolutions": {
47-
"angular": "~1.3"
48-
}
45+
]
4946
}

dist/forms-angular.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ var fng;
844844
if (instructionsArray) {
845845
for (var anInstruction = 0; anInstruction < instructionsArray.length; anInstruction++) {
846846
var info = instructionsArray[anInstruction];
847-
if (anInstruction === 0 && topLevel && !options.schema.match(/$_schema_/)) {
847+
if (anInstruction === 0 && topLevel && !options.schema.match(/$_schema_/) && typeof info.add !== 'object') {
848848
info.add = info.add ? ' ' + info.add + ' ' : '';
849849
if (info.add.indexOf('ui-date') === -1 && !options.noautofocus && !info.containerType) {
850850
info.add = info.add + 'autofocus ';
@@ -2541,20 +2541,33 @@ var fng;
25412541
function pluginHelper(formMarkupHelper) {
25422542
return {
25432543
extractFromAttr: function extractFromAttr(attr, directiveName) {
2544+
function deserialize(str) {
2545+
var retVal = str.replace(/&quot;/g, '"');
2546+
if (retVal === 'true') {
2547+
retVal = true;
2548+
}
2549+
else if (retVal === 'false') {
2550+
retVal = false;
2551+
}
2552+
else if (!isNaN(parseFloat(retVal)) && isFinite(retVal)) {
2553+
retVal = parseFloat(retVal);
2554+
}
2555+
return retVal;
2556+
}
25442557
var info = {};
25452558
var options = { formStyle: attr.formstyle };
25462559
var directiveOptions = {};
2547-
var directiveNameLength = directiveName.length;
2560+
var directiveNameLength = directiveName ? directiveName.length : 0;
25482561
for (var prop in attr) {
25492562
if (attr.hasOwnProperty(prop)) {
25502563
if (prop.slice(0, 6) === 'fngFld') {
2551-
info[prop.slice(6).toLowerCase()] = attr[prop].replace(/&quot;/g, '"');
2564+
info[prop.slice(6).toLowerCase()] = deserialize(attr[prop]);
25522565
}
25532566
else if (prop.slice(0, 6) === 'fngOpt') {
2554-
options[prop.slice(6).toLowerCase()] = attr[prop].replace(/&quot;/g, '"');
2567+
options[prop.slice(6).toLowerCase()] = deserialize(attr[prop]);
25552568
}
2556-
else if (prop.slice(0, directiveNameLength) === directiveName) {
2557-
directiveOptions[prop.slice(directiveNameLength).toLowerCase()] = attr[prop].replace(/&quot;/g, '"');
2569+
else if (directiveName && prop.slice(0, directiveNameLength) === directiveName) {
2570+
directiveOptions[prop.slice(directiveNameLength).toLowerCase()] = deserialize(attr[prop]);
25582571
}
25592572
}
25602573
}

dist/forms-angular.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/forms-angular.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/directives/form.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ module fng.directives {
413413
if (instructionsArray) {
414414
for (var anInstruction = 0; anInstruction < instructionsArray.length; anInstruction++) {
415415
var info = instructionsArray[anInstruction];
416-
if (anInstruction === 0 && topLevel && !options.schema.match(/$_schema_/)) {
416+
if (anInstruction === 0 && topLevel && !options.schema.match(/$_schema_/) && typeof info.add !== 'object') {
417417
info.add = info.add ? ' ' + info.add + ' ' : '';
418418
if (info.add.indexOf('ui-date') === -1 && !options.noautofocus && !info.containerType) {
419419
info.add = info.add + 'autofocus ';

js/services/plugin-helper.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,31 @@ module fng.services {
99
export function pluginHelper(formMarkupHelper) {
1010
return {
1111
extractFromAttr: function extractFromAttr(attr, directiveName) {
12+
13+
function deserialize(str) {
14+
var retVal = str.replace(/&quot;/g, '"')
15+
if (retVal === 'true') {
16+
retVal = true;
17+
} else if (retVal === 'false') {
18+
retVal = false;
19+
} else if (!isNaN(parseFloat(retVal)) && isFinite(retVal)) {
20+
retVal = parseFloat(retVal);
21+
}
22+
return retVal;
23+
}
24+
1225
var info = {};
1326
var options = {formStyle: attr.formstyle};
1427
var directiveOptions = {};
15-
var directiveNameLength = directiveName.length;
28+
var directiveNameLength = directiveName ? directiveName.length : 0;
1629
for (var prop in attr) {
1730
if (attr.hasOwnProperty(prop)) {
1831
if (prop.slice(0, 6) === 'fngFld') {
19-
info[prop.slice(6).toLowerCase()] = attr[prop].replace(/&quot;/g, '"');
32+
info[prop.slice(6).toLowerCase()] = deserialize(attr[prop]);
2033
} else if (prop.slice(0, 6) === 'fngOpt') {
21-
options[prop.slice(6).toLowerCase()] = attr[prop].replace(/&quot;/g, '"');
22-
} else if (prop.slice(0, directiveNameLength) === directiveName) {
23-
directiveOptions[prop.slice(directiveNameLength).toLowerCase()] = attr[prop].replace(/&quot;/g, '"');
34+
options[prop.slice(6).toLowerCase()] = deserialize(attr[prop]);
35+
} else if (directiveName && prop.slice(0, directiveNameLength) === directiveName) {
36+
directiveOptions[prop.slice(directiveNameLength).toLowerCase()] = deserialize(attr[prop]);
2437
}
2538
}
2639
}

0 commit comments

Comments
 (0)