@felte/core
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -189,2 +189,17 @@ import { __rest } from './external/.pnpm/tslib@2.3.1/external/tslib/tslib.es6.js'; | ||
} | ||
function setSelectValue(target) { | ||
if (!target.multiple) { | ||
data.update(($data) => { | ||
return _set($data, getPath(target), target.value); | ||
}); | ||
} | ||
else { | ||
const selectedOptions = Array.from(target.options) | ||
.filter((opt) => opt.selected) | ||
.map((opt) => opt.value); | ||
data.update(($data) => { | ||
return _set($data, getPath(target), selectedOptions); | ||
}); | ||
} | ||
} | ||
function handleInput(e) { | ||
@@ -220,3 +235,3 @@ const target = e.target; | ||
} | ||
if (isSelectElement(target) || target.type === 'hidden') { | ||
if (target.type === 'hidden') { | ||
data.update(($data) => { | ||
@@ -226,9 +241,11 @@ return _set($data, getPath(target), target.value); | ||
} | ||
if (!isInputElement(target)) | ||
if (isSelectElement(target)) | ||
setSelectValue(target); | ||
else if (!isInputElement(target)) | ||
return; | ||
if (target.type === 'checkbox') | ||
else if (target.type === 'checkbox') | ||
setCheckboxValues(target); | ||
if (target.type === 'radio') | ||
else if (target.type === 'radio') | ||
setRadioValues(target); | ||
if (target.type === 'file') | ||
else if (target.type === 'file') | ||
setFileValue(target); | ||
@@ -235,0 +252,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { isFormControl, isFieldSetElement, isInputElement } from './typeGuards.js'; | ||
import { isFormControl, isFieldSetElement, isInputElement, isSelectElement } from './typeGuards.js'; | ||
import { _get } from './get.js'; | ||
@@ -103,2 +103,16 @@ import { _set } from './set.js'; | ||
} | ||
else if (isSelectElement(el)) { | ||
const multiple = el.multiple; | ||
if (!multiple) { | ||
defaultData = _set(defaultData, elName, el.value); | ||
} | ||
else { | ||
const selectedOptions = Array.from(el.options) | ||
.filter((opt) => opt.selected) | ||
.map((opt) => opt.value); | ||
defaultData = _set(defaultData, elName, selectedOptions); | ||
} | ||
defaultTouched = _set(defaultTouched, elName, false); | ||
continue; | ||
} | ||
const inputValue = getInputTextOrNumber(el); | ||
@@ -111,2 +125,3 @@ defaultData = _set(defaultData, elName, inputValue); | ||
function setControlValue(el, value) { | ||
var _a; | ||
if (!isFormControl(el)) | ||
@@ -147,2 +162,28 @@ return; | ||
} | ||
else if (isSelectElement(el)) { | ||
const multiple = el.multiple; | ||
if (!multiple) { | ||
el.value = String(fieldValue !== null && fieldValue !== void 0 ? fieldValue : ''); | ||
for (const option of el.options) { | ||
if (option.value === fieldValue) { | ||
option.selected = true; | ||
} | ||
else { | ||
option.selected = false; | ||
} | ||
} | ||
} | ||
else if (Array.isArray(fieldValue)) { | ||
el.value = String((_a = fieldValue[0]) !== null && _a !== void 0 ? _a : ''); | ||
for (const option of el.options) { | ||
if (fieldValue.includes(option.value)) { | ||
option.selected = true; | ||
} | ||
else { | ||
option.selected = false; | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
el.value = String(fieldValue !== null && fieldValue !== void 0 ? fieldValue : ''); | ||
@@ -149,0 +190,0 @@ } |
{ | ||
"name": "@felte/core", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Core utility for Felte's integration with front-end frameworks", | ||
@@ -27,3 +27,3 @@ "main": "dist/cjs/index.cjs", | ||
"dependencies": { | ||
"@felte/common": "1.0.0" | ||
"@felte/common": "1.0.1" | ||
}, | ||
@@ -30,0 +30,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
431396
3832
+ Added@felte/common@1.0.1(transitive)
- Removed@felte/common@1.0.0(transitive)
Updated@felte/common@1.0.1