From 032512e815cfd4d1264bc8da914f02272491bb01 Mon Sep 17 00:00:00 2001 From: Lars Olav Torvik Date: Wed, 5 Jun 2024 13:22:40 +0200 Subject: [PATCH 1/2] Fix problem with calculateValue and number --- .../src/formio/components/base/BaseComponent.tsx | 2 +- .../formio/components/extensions/currency/Currency.form.ts | 6 +++++- .../src/formio/components/extensions/number/Number.form.ts | 6 +++++- .../src/formio/components/extensions/number/Number.ts | 7 ++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/shared-components/src/formio/components/base/BaseComponent.tsx b/packages/shared-components/src/formio/components/base/BaseComponent.tsx index ff725a717..50c3eddf9 100644 --- a/packages/shared-components/src/formio/components/base/BaseComponent.tsx +++ b/packages/shared-components/src/formio/components/base/BaseComponent.tsx @@ -50,7 +50,7 @@ class BaseComponent extends FormioReactComponent { return ( <> {this.t(this.component?.label ?? '')} - {this.isRequired() && !this.component?.readOnly ? '' : showOptional && ` (${this.t('valgfritt')})`} + {this.isRequired() || !!this.component?.readOnly ? '' : showOptional && ` (${this.t('valgfritt')})`} {showDiffTag && this.getDiffTag()} ); diff --git a/packages/shared-components/src/formio/components/extensions/currency/Currency.form.ts b/packages/shared-components/src/formio/components/extensions/currency/Currency.form.ts index d74dd20c9..609339ed8 100644 --- a/packages/shared-components/src/formio/components/extensions/currency/Currency.form.ts +++ b/packages/shared-components/src/formio/components/extensions/currency/Currency.form.ts @@ -1,11 +1,12 @@ import editFormApi from '../../base/editForm/api'; import editFormConditional from '../../base/editForm/conditional'; +import editFormData from '../../base/editForm/data'; import editFormDisplay from '../../base/editForm/display'; import editFormTabs from '../../base/editForm/editFormTabs'; import editFormValidation from '../../base/editForm/validation'; const currencyForm = () => { - const { api, conditional, createTabs, display, validation } = editFormTabs; + const { api, conditional, createTabs, display, validation, data } = editFormTabs; // prettier-ignore return createTabs( @@ -16,6 +17,9 @@ const currencyForm = () => { editFormDisplay.description(), editFormDisplay.additionalDescription(), ]), + data([ + editFormData.calculateValue(), + ]), validation([ editFormValidation.required(), editFormValidation.customValidation(), diff --git a/packages/shared-components/src/formio/components/extensions/number/Number.form.ts b/packages/shared-components/src/formio/components/extensions/number/Number.form.ts index fb38f3d43..b886a1f3c 100644 --- a/packages/shared-components/src/formio/components/extensions/number/Number.form.ts +++ b/packages/shared-components/src/formio/components/extensions/number/Number.form.ts @@ -1,11 +1,12 @@ import editFormApi from '../../base/editForm/api'; import editFormConditional from '../../base/editForm/conditional'; +import editFormData from '../../base/editForm/data'; import editFormDisplay from '../../base/editForm/display'; import editFormTabs from '../../base/editForm/editFormTabs'; import editFormValidation from '../../base/editForm/validation'; const numberForm = () => { - const { api, conditional, createTabs, display, validation } = editFormTabs; + const { api, conditional, createTabs, display, validation, data } = editFormTabs; // prettier-ignore return createTabs( @@ -16,6 +17,9 @@ const numberForm = () => { editFormDisplay.description(), editFormDisplay.additionalDescription(), ]), + data([ + editFormData.calculateValue(), + ]), validation([ editFormValidation.required(), editFormValidation.minNumber(), diff --git a/packages/shared-components/src/formio/components/extensions/number/Number.ts b/packages/shared-components/src/formio/components/extensions/number/Number.ts index c9e687d88..5c3017f74 100644 --- a/packages/shared-components/src/formio/components/extensions/number/Number.ts +++ b/packages/shared-components/src/formio/components/extensions/number/Number.ts @@ -52,7 +52,7 @@ class Number extends TextField { // Get data value from parent instead of formatted number from this.getValue() const value = super.getValue(); - if (value === '' || value === undefined) { + if (value === '' || value === undefined || !!this.component?.calculateValue) { return; } @@ -94,6 +94,11 @@ class Number extends TextField { return numberUtils.toLocaleString(super.getValue()); } + setValueOnReactInstance(value) { + // This is needed to handle formatting after calculate value + super.setValueOnReactInstance(numberUtils.toLocaleString(value)); + } + replaceCommasAndSpaces(value: string) { return value?.replace(/,/g, '.').replace(/\s/g, ''); } From a39408c483b763339f67dfeea959487a654d0c1e Mon Sep 17 00:00:00 2001 From: Lars Olav Torvik Date: Wed, 5 Jun 2024 13:37:46 +0200 Subject: [PATCH 2/2] Remove optional label for readonly checkbox --- packages/fyllut/cypress/e2e/components/checkbox.cy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fyllut/cypress/e2e/components/checkbox.cy.ts b/packages/fyllut/cypress/e2e/components/checkbox.cy.ts index a08c60c47..c8648f9c2 100644 --- a/packages/fyllut/cypress/e2e/components/checkbox.cy.ts +++ b/packages/fyllut/cypress/e2e/components/checkbox.cy.ts @@ -122,10 +122,10 @@ describe('Checkbox', () => { cy.findByRole('checkbox', { name: 'Normal checkbox (valgfritt)' }).should('be.checked'); cy.findByRole('checkbox', { name: 'Required checkbox' }).should('be.checked'); - cy.findByRole('checkbox', { name: 'ReadOnly checkbox checked (valgfritt)' }).should('be.checked'); + cy.findByRole('checkbox', { name: 'ReadOnly checkbox checked' }).should('be.checked'); cy.findByRole('checkbox', { name: 'Checkbox description (valgfritt)' }).should('be.checked'); - cy.findByRole('checkbox', { name: 'ReadOnly checkbox (valgfritt)' }).should('not.be.checked'); + cy.findByRole('checkbox', { name: 'ReadOnly checkbox' }).should('not.be.checked'); }); }); });