Skip to content

Commit

Permalink
Renames option parseValues to dynamicTyping in parseForm() method
Browse files Browse the repository at this point in the history
Renames option `smartParsing` to `smartTyping` in `parseForm()` method
Renames option `trimValues` to `trim` in `parseForm()` method
  • Loading branch information
jalik committed Dec 3, 2017
1 parent 158e7a8 commit 089f32f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 51 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ First of all, you have to define fields types in the HTML code using the `data-t
<input name="anything_2" type="text" value="false" data-type="auto">
```

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.
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.

## Getting fields from a form

Expand Down Expand Up @@ -73,11 +73,11 @@ const fields = FormUtils.parseForm(form, {
// Replace empty strings with null
nullify: true,
// Parse values to the best type (ex: "001" => 1)
parseValues: true,
dynamicTyping: true,
// Parse values based on field type (ex: type="number" will parse to number)
smartParsing: true,
smartTyping: true,
// Remove extra spaces
trimValues: true
trim: true
});
```

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

## Changelog

### v1.0.4
- Renames option `parseValues` to `dynamicTyping` in `parseForm()` method
- Renames option `smartParsing` to `smartTyping` in `parseForm()` method
- Renames option `trimValues` to `trim` in `parseForm()` method

### v1.0.3
- Fixes error with unchecked fields being parsed
- Changes signature of method `cleanFunction(value, field)` called by `parseForm()`
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jk-form-parser",
"version": "1.0.3",
"version": "1.0.4",
"description": "Parse complex forms with minimum effort.",
"license": "MIT",
"keywords": [
Expand Down
26 changes: 20 additions & 6 deletions src/jk-form-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,31 @@ export default {
// Default options
options = this.extend({
cleanFunction: null,
dynamicTyping: true,
filterFunction: null,
ignoreButtons: true,
ignoreDisabled: true,
ignoreEmpty: false,
ignoreUnchecked: false,
nullify: true,
parseValues: true,
smartParsing: true,
trimValues: true
smartTyping: true,
trim: true
}, options);

// Check deprecated options
if (options.hasOwnProperty("parseValues")) {
console.warn(`option "parseValues" is deprecated, rename it to "dynamicTyping" instead`);
options.dynamicTyping = options.parseValues;
}
if (options.hasOwnProperty("smartParsing")) {
console.warn(`option "smartParsing" is deprecated, rename it to "smartTyping" instead`);
options.smartTyping = options.smartParsing;
}
if (options.hasOwnProperty("trimValues")) {
console.warn(`option "trimValues" is deprecated, rename it to "trim" instead`);
options.trim = options.trimValues;
}

let fields = {};
const elements = form.elements;

Expand Down Expand Up @@ -178,7 +192,7 @@ export default {
break;
}

if (options.parseValues) {
if (options.dynamicTyping) {
// Parse value excepted for special fields
if ((!isCheckable || field.checked)
&& !this.contains(["email", "file", "password", "search", "url"], field.type)
Expand Down Expand Up @@ -226,7 +240,7 @@ export default {
}
}
// Parse value using the "type" attribute
else if (options.smartParsing) {
else if (options.smartTyping) {
switch (field.type) {
case "number":
case "range":
Expand All @@ -253,7 +267,7 @@ export default {
}

// Removes extra spaces
if (options.trimValues && !this.contains(["password"], field.type)) {
if (options.trim && !this.contains(["password"], field.type)) {
if (value instanceof Array) {
for (let k = 0; k < value.length; k += 1) {
if (typeof value[k] === "string" && value[k].length) {
Expand Down
Loading

0 comments on commit 089f32f

Please sign in to comment.