diff --git a/src/components/common/VnSelect.vue b/src/components/common/VnSelect.vue index 14005e1cc..1a41d261a 100644 --- a/src/components/common/VnSelect.vue +++ b/src/components/common/VnSelect.vue @@ -8,7 +8,14 @@ import dataByOrder from 'src/utils/dataByOrder'; const emit = defineEmits(['update:modelValue', 'update:options', 'remove']); const $attrs = useAttrs(); const { t } = useI18n(); -const { isRequired, requiredFieldRule } = useRequired($attrs); + +const isRequired = computed(() => { + return useRequired($attrs).isRequired; +}); +const requiredFieldRule = computed(() => { + return useRequired($attrs).requiredFieldRule; +}); + const $props = defineProps({ modelValue: { type: [String, Number, Object], diff --git a/src/composables/useRequired.js b/src/composables/useRequired.js index e650c91f5..d211b96b4 100644 --- a/src/composables/useRequired.js +++ b/src/composables/useRequired.js @@ -2,8 +2,14 @@ import { useValidator } from 'src/composables/useValidator'; export function useRequired($attrs) { const { validations } = useValidator(); - - const isRequired = Object.keys($attrs).includes('required'); + const hasRequired = Object.keys($attrs).includes('required'); + let isRequired = false; + if (hasRequired) { + const required = $attrs['required']; + if (typeof required === 'boolean') { + isRequired = required; + } + } const requiredFieldRule = (val) => validations().required(isRequired, val); return { diff --git a/src/pages/Customer/Card/CustomerFiscalData.vue b/src/pages/Customer/Card/CustomerFiscalData.vue index 24d8d1e5d..673c7dda9 100644 --- a/src/pages/Customer/Card/CustomerFiscalData.vue +++ b/src/pages/Customer/Card/CustomerFiscalData.vue @@ -67,6 +67,7 @@ function handleLocation(data, location) { option-label="vat" option-value="id" v-model="data.sageTaxTypeFk" + data-cy="sageTaxTypeFk" :required="data.isTaxDataChecked" /> diff --git a/src/utils/dataByOrder.js b/src/utils/dataByOrder.js index 1bdedb8a1..eb4a4f586 100644 --- a/src/utils/dataByOrder.js +++ b/src/utils/dataByOrder.js @@ -1,6 +1,7 @@ function orderData(data, order) { if (typeof order === 'function') return data.sort(data); if (typeof order === 'string') order = [order]; + if (!Array.isArray(data)) return []; if (Array.isArray(order)) { let orderComp = []; diff --git a/test/cypress/integration/client/clientFiscalData.spec.js b/test/cypress/integration/client/clientFiscalData.spec.js index e337c26f8..05e0772e9 100644 --- a/test/cypress/integration/client/clientFiscalData.spec.js +++ b/test/cypress/integration/client/clientFiscalData.spec.js @@ -3,11 +3,16 @@ describe('Client fiscal data', () => { beforeEach(() => { cy.viewport(1280, 720); cy.login('developer'); - cy.visit('#/customer/1110/fiscal-data', { + cy.visit('#/customer/1107/fiscal-data', { timeout: 5000, }); }); - it('Should load layout', () => { + it('Should change required value when change customer', () => { cy.get('.q-card').should('be.visible'); + cy.dataCy('sageTaxTypeFk').filter('input').should('not.have.attr', 'required'); + cy.get('#searchbar input').clear(); + cy.get('#searchbar input').type('1{enter}'); + cy.get('.q-item > .q-item__label').should('have.text', ' #1'); + cy.dataCy('sageTaxTypeFk').filter('input').should('have.attr', 'required'); }); });