|
| 1 | +import bind, { isCheckbox, isRadio, safeParseBoolean } from '../utils/bind' |
1 | 2 | import { evaluateLater } from '../evaluator'
|
2 | 3 | import { directive } from '../directives'
|
3 | 4 | import { mutateDom } from '../mutation'
|
4 | 5 | import { nextTick } from '../nextTick'
|
5 |
| -import bind, { safeParseBoolean } from '../utils/bind' |
6 |
| -import on from '../utils/on' |
7 | 6 | import { isCloning } from '../clone'
|
| 7 | +import on from '../utils/on' |
8 | 8 |
|
9 | 9 | directive('model', (el, { modifiers, expression }, { effect, cleanup }) => {
|
10 | 10 | let scopeTarget = el
|
@@ -71,7 +71,7 @@ directive('model', (el, { modifiers, expression }, { effect, cleanup }) => {
|
71 | 71 |
|
72 | 72 | if (modifiers.includes('fill'))
|
73 | 73 | if ([undefined, null, ''].includes(getValue())
|
74 |
| - || (el.type === 'checkbox' && Array.isArray(getValue())) |
| 74 | + || (isCheckbox(el) && Array.isArray(getValue())) |
75 | 75 | || (el.tagName.toLowerCase() === 'select' && el.multiple)) {
|
76 | 76 | setValue(
|
77 | 77 | getInputValue(el, modifiers, { target: el }, getValue())
|
@@ -138,7 +138,7 @@ function getInputValue(el, modifiers, event, currentValue) {
|
138 | 138 | // so we return event.target.value instead of event.detail
|
139 | 139 | if (event instanceof CustomEvent && event.detail !== undefined)
|
140 | 140 | return event.detail !== null && event.detail !== undefined ? event.detail : event.target.value
|
141 |
| - else if (el.type === 'checkbox') { |
| 141 | + else if (isCheckbox(el)) { |
142 | 142 | // If the data we are binding to is an array, toggle its value inside the array.
|
143 | 143 | if (Array.isArray(currentValue)) {
|
144 | 144 | let newValue = null;
|
@@ -176,7 +176,7 @@ function getInputValue(el, modifiers, event, currentValue) {
|
176 | 176 | } else {
|
177 | 177 | let newValue
|
178 | 178 |
|
179 |
| - if (el.type === 'radio') { |
| 179 | + if (isRadio(el)) { |
180 | 180 | if (event.target.checked) {
|
181 | 181 | newValue = event.target.value
|
182 | 182 | } else {
|
|
0 commit comments