In my application, the user provides style code inside an input field. I want to add a popup confirmation modal with a message containing the number of style codes provided. I have the following:
<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 key part is this
methods: { async syncProducts() { let confirmationText = `Do you want to ${this.productsToSyncAmount} sync products?`
I don't understand why this code generates undefined numbers based on the length and displays me the message Do you want to undefined sync products?
. Inside the console I have:
[Vue warn]: Invalid prop: Type check for prop 'formulateValue' failed. Expected object, got array
how to solve this problem?
I think the problem is that you are providing an array to
FormulateForm
. According to the documentation, it requires an object.https://vueformulate.com/guide/forms/#setting-initial -value