In my app user provides style codes inside input field. I want to add popup confirmation modal which will have message containing the number of provided style codes. I've got below:
<template>
<h4>Style number</h4>
<FormulateForm v-model="styleCodes">
<FormulateInput
name="product_codes"
placeholder="Style number"
/>
<button
type="button"
class="btn btn-primary"
@click="syncProducts"
>
Sync
</button>
</FormulateForm>
</template>
<script>
export default {
name: 'SyncProducts',
data() {
return {
styleCodes: [],
}
},
computed: {
productsToSyncAmount () {
return this.styleCodes.length
},
methods: {
async syncProducts() {
let confirmationText = `Do you want to ${this.productsToSyncAmount} sync products?`
if (this.productsToSyncAmount === 0) {
ModalController.showToast('', 'Type product codes for sync first, please!', 'warning')
}
else if (await ModalController.showConfirmation('Confirmation', confirmationText)) {
try {
ModalController.showLoader()
await createApparelMagicProductsRequest(this, this.styleCodes)
} catch (data) {
const errorMessage = `Error occurred during queueing products to sync - `
ModalController.showToast('', errorMessage + data?.message, 'error')
} finally {
this.styleCodes = []
}
}
},
}
}
</script>
I think the crucial part is that one
methods: {
async syncProducts() {
let confirmationText = `Do you want to ${this.productsToSyncAmount} sync products?`
I don't get it why this code produces undefined number from length and show me message Do you want to undefined sync products?. Inside the console I've got:
[Vue warn]: Invalid prop: type check failed for prop "formulateValue". Expected Object, got Array
How to fix that?
I think the problem is that you provide an array to FormulateForm.
According to the docs it expects an object.
https://vueformulate.com/guide/forms/#setting-initial-values