Skip to content

Commit 089f32f

Browse files
committed
Renames option parseValues to dynamicTyping in parseForm() method
Renames option `smartParsing` to `smartTyping` in `parseForm()` method Renames option `trimValues` to `trim` in `parseForm()` method
1 parent 158e7a8 commit 089f32f

File tree

4 files changed

+87
-51
lines changed

4 files changed

+87
-51
lines changed

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ First of all, you have to define fields types in the HTML code using the `data-t
2929
<input name="anything_2" type="text" value="false" data-type="auto">
3030
```
3131

32-
If no `data-type` attribute is set, the `type` attribute will be used (for `input` elements at least), this behavior is active by default with the combination of this options `{parseValues: true, smartParsing: true}` in the `parseForm()` function.
32+
If no `data-type` attribute is set, the `type` attribute will be used (for `input` elements at least), this behavior is active by default with the combination of this options `{dynamicTyping: true, smartTyping: true}` in the `parseForm()` function.
3333

3434
## Getting fields from a form
3535

@@ -73,11 +73,11 @@ const fields = FormUtils.parseForm(form, {
7373
// Replace empty strings with null
7474
nullify: true,
7575
// Parse values to the best type (ex: "001" => 1)
76-
parseValues: true,
76+
dynamicTyping: true,
7777
// Parse values based on field type (ex: type="number" will parse to number)
78-
smartParsing: true,
78+
smartTyping: true,
7979
// Remove extra spaces
80-
trimValues: true
80+
trim: true
8181
});
8282
```
8383

@@ -367,6 +367,11 @@ const fields = FormUtils.parseForm(form, {
367367

368368
## Changelog
369369

370+
### v1.0.4
371+
- Renames option `parseValues` to `dynamicTyping` in `parseForm()` method
372+
- Renames option `smartParsing` to `smartTyping` in `parseForm()` method
373+
- Renames option `trimValues` to `trim` in `parseForm()` method
374+
370375
### v1.0.3
371376
- Fixes error with unchecked fields being parsed
372377
- Changes signature of method `cleanFunction(value, field)` called by `parseForm()`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jk-form-parser",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Parse complex forms with minimum effort.",
55
"license": "MIT",
66
"keywords": [

src/jk-form-parser.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,31 @@ export default {
107107
// Default options
108108
options = this.extend({
109109
cleanFunction: null,
110+
dynamicTyping: true,
110111
filterFunction: null,
111112
ignoreButtons: true,
112113
ignoreDisabled: true,
113114
ignoreEmpty: false,
114115
ignoreUnchecked: false,
115116
nullify: true,
116-
parseValues: true,
117-
smartParsing: true,
118-
trimValues: true
117+
smartTyping: true,
118+
trim: true
119119
}, options);
120120

121+
// Check deprecated options
122+
if (options.hasOwnProperty("parseValues")) {
123+
console.warn(`option "parseValues" is deprecated, rename it to "dynamicTyping" instead`);
124+
options.dynamicTyping = options.parseValues;
125+
}
126+
if (options.hasOwnProperty("smartParsing")) {
127+
console.warn(`option "smartParsing" is deprecated, rename it to "smartTyping" instead`);
128+
options.smartTyping = options.smartParsing;
129+
}
130+
if (options.hasOwnProperty("trimValues")) {
131+
console.warn(`option "trimValues" is deprecated, rename it to "trim" instead`);
132+
options.trim = options.trimValues;
133+
}
134+
121135
let fields = {};
122136
const elements = form.elements;
123137

@@ -178,7 +192,7 @@ export default {
178192
break;
179193
}
180194

181-
if (options.parseValues) {
195+
if (options.dynamicTyping) {
182196
// Parse value excepted for special fields
183197
if ((!isCheckable || field.checked)
184198
&& !this.contains(["email", "file", "password", "search", "url"], field.type)
@@ -226,7 +240,7 @@ export default {
226240
}
227241
}
228242
// Parse value using the "type" attribute
229-
else if (options.smartParsing) {
243+
else if (options.smartTyping) {
230244
switch (field.type) {
231245
case "number":
232246
case "range":
@@ -253,7 +267,7 @@ export default {
253267
}
254268

255269
// Removes extra spaces
256-
if (options.trimValues && !this.contains(["password"], field.type)) {
270+
if (options.trim && !this.contains(["password"], field.type)) {
257271
if (value instanceof Array) {
258272
for (let k = 0; k < value.length; k += 1) {
259273
if (typeof value[k] === "string" && value[k].length) {

0 commit comments

Comments
 (0)