mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
migration: vue3 COMPONENT_V_MODEL
This commit is contained in:
parent
cc98de76b5
commit
2898a4f5bd
9 changed files with 45 additions and 46 deletions
|
@ -2,24 +2,24 @@
|
||||||
<BInputGroup v-bind="$attrs">
|
<BInputGroup v-bind="$attrs">
|
||||||
<InputItem
|
<InputItem
|
||||||
:id="id"
|
:id="id"
|
||||||
:value="value.localPart"
|
:modelValue="modelValue.localPart"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:state="state"
|
:state="state"
|
||||||
:aria-describedby="id + 'local-part-desc'"
|
:aria-describedby="id + 'local-part-desc'"
|
||||||
@input="onInput('localPart', $event)"
|
@update:modelValue="onInput('localPart', $event)"
|
||||||
@blur="$parent.$emit('touch')"
|
@blur="$parent.$emit('touch')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<BInputGroupAppend>
|
<BInputGroupAppend>
|
||||||
<BInputGroupText>{{ value.separator }}</BInputGroupText>
|
<BInputGroupText>{{ modelValue.separator }}</BInputGroupText>
|
||||||
</BInputGroupAppend>
|
</BInputGroupAppend>
|
||||||
|
|
||||||
<BInputGroupAppend>
|
<BInputGroupAppend>
|
||||||
<SelectItem
|
<SelectItem
|
||||||
:value="value.domain"
|
:modelValue="modelValue.domain"
|
||||||
:choices="choices"
|
:choices="choices"
|
||||||
:aria-describedby="id + 'domain-desc'"
|
:aria-describedby="id + 'domain-desc'"
|
||||||
@input="onInput('domain', $event)"
|
@update:modelValue="onInput('domain', $event)"
|
||||||
@blur="$parent.$emit('touch')"
|
@blur="$parent.$emit('touch')"
|
||||||
/>
|
/>
|
||||||
</BInputGroupAppend>
|
</BInputGroupAppend>
|
||||||
|
@ -45,8 +45,7 @@ export default {
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
// `value` is actually passed thru the `v-model` directive
|
modelValue: { type: Object, required: true },
|
||||||
value: { type: Object, required: true },
|
|
||||||
choices: { type: Array, required: true },
|
choices: { type: Array, required: true },
|
||||||
placeholder: { type: String, default: null },
|
placeholder: { type: String, default: null },
|
||||||
id: { type: String, default: null },
|
id: { type: String, default: null },
|
||||||
|
@ -55,10 +54,10 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onInput(key, value) {
|
onInput(key, modelValue) {
|
||||||
this.$emit('input', {
|
this.$emit('update:modelValue', {
|
||||||
...this.value,
|
...this.modelValue,
|
||||||
[key]: value,
|
[key]: modelValue,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
v-bind="props"
|
v-bind="props"
|
||||||
:is="component"
|
:is="component"
|
||||||
v-on="$listeners"
|
v-on="$listeners"
|
||||||
:value="value"
|
:modelValue="modelValue"
|
||||||
|
@update:modelValue="$emit('update:modelValue', $event)"
|
||||||
:state="state"
|
:state="state"
|
||||||
:required="validation ? 'required' in validation : false"
|
:required="validation ? 'required' in validation : false"
|
||||||
/>
|
/>
|
||||||
|
@ -62,7 +63,7 @@ export default {
|
||||||
link: { type: Object, default: null },
|
link: { type: Object, default: null },
|
||||||
// Rendered field component props
|
// Rendered field component props
|
||||||
component: { type: String, default: 'InputItem' },
|
component: { type: String, default: 'InputItem' },
|
||||||
value: { type: null, default: null },
|
modelValue: { type: null, default: null },
|
||||||
props: { type: Object, default: () => ({}) },
|
props: { type: Object, default: () => ({}) },
|
||||||
validation: { type: Object, default: null },
|
validation: { type: Object, default: null },
|
||||||
validationIndex: { type: Number, default: null },
|
validationIndex: { type: Number, default: null },
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
<template>
|
<template>
|
||||||
|
<!-- FIXME vue3 - `modelValue`+`@update:model` doesn't work here, probably to the prop's name not being `value`. Sticking for now to `checked`+`@input` -->
|
||||||
<BFormCheckbox
|
<BFormCheckbox
|
||||||
v-model="checked"
|
:checked="modelValue"
|
||||||
|
@input="$emit('update:modelValue', $event)"
|
||||||
v-on="$listeners"
|
v-on="$listeners"
|
||||||
:id="id"
|
:id="id"
|
||||||
:aria-describedby="$parent.id + '__BV_description_'"
|
:aria-describedby="$parent.id + '__BV_description_'"
|
||||||
switch
|
switch
|
||||||
>
|
>
|
||||||
{{ label || $t(labels[checked]) }}
|
{{ label || $t(labels[modelValue]) }}
|
||||||
</BFormCheckbox>
|
</BFormCheckbox>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -16,16 +18,10 @@ export default {
|
||||||
name: 'CheckboxItem',
|
name: 'CheckboxItem',
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: { type: Boolean, required: true },
|
modelValue: { type: Boolean, required: true },
|
||||||
id: { type: String, default: null },
|
id: { type: String, default: null },
|
||||||
label: { type: String, default: null },
|
label: { type: String, default: null },
|
||||||
labels: { type: Object, default: () => ({ true: 'yes', false: 'no' }) },
|
labels: { type: Object, default: () => ({ true: 'yes', false: 'no' }) },
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
checked: this.value,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<BButtonGroup class="w-100">
|
<BButtonGroup class="w-100">
|
||||||
<BButton
|
<BButton
|
||||||
v-if="!this.required && this.value.file !== null"
|
v-if="!this.required && this.modelValue.file !== null"
|
||||||
@click="clearFiles"
|
@click="clearFiles"
|
||||||
variant="danger"
|
variant="danger"
|
||||||
>
|
>
|
||||||
|
@ -10,7 +10,7 @@
|
||||||
</BButton>
|
</BButton>
|
||||||
|
|
||||||
<BFormFile
|
<BFormFile
|
||||||
:value="value.file"
|
:modelValue="modelValue.file"
|
||||||
ref="input-file"
|
ref="input-file"
|
||||||
:id="id"
|
:id="id"
|
||||||
:required="required"
|
:required="required"
|
||||||
|
@ -35,7 +35,7 @@ export default {
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
id: { type: String, default: null },
|
id: { type: String, default: null },
|
||||||
value: { type: Object, default: () => ({ file: null }) },
|
modelValue: { type: Object, default: () => ({ file: null }) },
|
||||||
placeholder: { type: String, default: 'Choose a file or drop it here...' },
|
placeholder: { type: String, default: 'Choose a file or drop it here...' },
|
||||||
dropPlaceholder: { type: String, default: null },
|
dropPlaceholder: { type: String, default: null },
|
||||||
accept: { type: String, default: null },
|
accept: { type: String, default: null },
|
||||||
|
@ -46,7 +46,9 @@ export default {
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
_placeholder: function () {
|
_placeholder: function () {
|
||||||
return this.value.file === null ? this.placeholder : this.value.file.name
|
return this.modelValue.file === null
|
||||||
|
? this.placeholder
|
||||||
|
: this.modelValue.file.name
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -59,17 +61,17 @@ export default {
|
||||||
removed: false,
|
removed: false,
|
||||||
}
|
}
|
||||||
// Update the value with the new File and an empty content for now
|
// Update the value with the new File and an empty content for now
|
||||||
this.$emit('input', value)
|
this.$emit('update:modelValue', value)
|
||||||
|
|
||||||
// Asynchronously load the File content and update the value again
|
// Asynchronously load the File content and update the value again
|
||||||
getFileContent(file).then((content) => {
|
getFileContent(file).then((content) => {
|
||||||
this.$emit('input', { ...value, content })
|
this.$emit('update:modelValue', { ...value, content })
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
clearFiles() {
|
clearFiles() {
|
||||||
this.$refs['input-file'].reset()
|
this.$refs['input-file'].reset()
|
||||||
this.$emit('input', {
|
this.$emit('update:modelValue', {
|
||||||
file: null,
|
file: null,
|
||||||
content: '',
|
content: '',
|
||||||
current: false,
|
current: false,
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<BFormInput
|
<BFormInput
|
||||||
:value="value"
|
:modelValue="modelValue"
|
||||||
|
@update:modelValue="$emit('update:modelValue', $event)"
|
||||||
:id="id"
|
:id="id"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:type="type"
|
:type="type"
|
||||||
|
@ -22,7 +23,7 @@ export default {
|
||||||
name: 'InputItem',
|
name: 'InputItem',
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: { type: [String, Number], default: null },
|
modelValue: { type: [String, Number], default: null },
|
||||||
id: { type: String, default: null },
|
id: { type: String, default: null },
|
||||||
placeholder: { type: String, default: null },
|
placeholder: { type: String, default: null },
|
||||||
type: { type: String, default: 'text' },
|
type: { type: String, default: 'text' },
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
<template>
|
<template>
|
||||||
<BFormSelect
|
<BFormSelect
|
||||||
:value="value"
|
:modelValue="modelValue"
|
||||||
|
@update:modelValue="$emit('update:modelValue', $event)"
|
||||||
:id="id"
|
:id="id"
|
||||||
:options="choices"
|
:options="choices"
|
||||||
:required="required"
|
:required="required"
|
||||||
v-on="$listeners"
|
v-on="$listeners"
|
||||||
@blur.native="$emit('blur', value)"
|
@blur.native="$emit('blur', modelValue)"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@ -15,7 +16,7 @@ export default {
|
||||||
name: 'SelectItem',
|
name: 'SelectItem',
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: { type: [String, null], default: null },
|
modelValue: { type: [String, null], default: null },
|
||||||
id: { type: String, default: null },
|
id: { type: String, default: null },
|
||||||
choices: { type: [Array, Object], required: true },
|
choices: { type: [Array, Object], required: true },
|
||||||
required: { type: Boolean, default: false },
|
required: { type: Boolean, default: false },
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<BFormTags
|
<BFormTags
|
||||||
v-model="tags"
|
:value="modelValue"
|
||||||
|
@input="$emit('update:modelValue', $event)"
|
||||||
:id="id"
|
:id="id"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:required="required"
|
:required="required"
|
||||||
|
@ -19,13 +20,8 @@ export default {
|
||||||
compatConfig: { MODE: 3 },
|
compatConfig: { MODE: 3 },
|
||||||
name: 'TagsItem',
|
name: 'TagsItem',
|
||||||
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
tags: this.value,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
props: {
|
props: {
|
||||||
value: { type: Array, default: null },
|
modelValue: { type: Array, default: null },
|
||||||
id: { type: String, default: null },
|
id: { type: String, default: null },
|
||||||
placeholder: { type: String, default: null },
|
placeholder: { type: String, default: null },
|
||||||
limit: { type: Number, default: null },
|
limit: { type: Number, default: null },
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
<BFormTags
|
<BFormTags
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
v-on="$listeners"
|
v-on="$listeners"
|
||||||
:value="value"
|
:modelValue="modelValue"
|
||||||
|
@update:modelValue="$emit('update:modelValue', $event)"
|
||||||
:id="id"
|
:id="id"
|
||||||
size="lg"
|
size="lg"
|
||||||
class="p-0 border-0"
|
class="p-0 border-0"
|
||||||
|
@ -99,7 +100,7 @@ export default {
|
||||||
inheritAttrs: false,
|
inheritAttrs: false,
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: { type: Array, required: true },
|
modelValue: { type: Array, required: true },
|
||||||
options: { type: Array, required: true },
|
options: { type: Array, required: true },
|
||||||
id: { type: String, required: true },
|
id: { type: String, required: true },
|
||||||
placeholder: { type: String, default: null },
|
placeholder: { type: String, default: null },
|
||||||
|
@ -129,7 +130,8 @@ export default {
|
||||||
const criteria = this.criteria
|
const criteria = this.criteria
|
||||||
const options = this.options.filter((opt) => {
|
const options = this.options.filter((opt) => {
|
||||||
return (
|
return (
|
||||||
this.value.indexOf(opt) === -1 && !this.disabledItems.includes(opt)
|
this.modelValue.indexOf(opt) === -1 &&
|
||||||
|
!this.disabledItems.includes(opt)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
if (criteria) {
|
if (criteria) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<BFormTextarea
|
<BFormTextarea
|
||||||
:value="value"
|
:modelValue="modelValue"
|
||||||
|
@update:modelValue="$emit('update:modelValue', $event)"
|
||||||
:id="id"
|
:id="id"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:required="required"
|
:required="required"
|
||||||
|
@ -17,7 +18,7 @@ export default {
|
||||||
name: 'TextAreaItem',
|
name: 'TextAreaItem',
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
value: { type: String, default: null },
|
modelValue: { type: String, default: null },
|
||||||
id: { type: String, default: null },
|
id: { type: String, default: null },
|
||||||
placeholder: { type: String, default: null },
|
placeholder: { type: String, default: null },
|
||||||
type: { type: String, default: 'text' },
|
type: { type: String, default: 'text' },
|
||||||
|
|
Loading…
Reference in a new issue