Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components keeping original defaultValue when editing #5123

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/openforms/forms/tests/e2e_tests/test_form_designer.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,55 @@ def assertFormValues():

await assertFormValues()

@tag("dh-5104")
async def test_radio_component_default_value_empty_string(self):
@sync_to_async
def setUpTestData():
form = FormFactory.create()
FormStepFactory.create(form=form)
return form

await create_superuser()
form = await setUpTestData()
admin_url = str(
furl(self.live_server_url)
/ reverse("admin:forms_form_change", args=(form.pk,))
)

async with browser_page() as page:
await self._admin_login(page)
await page.goto(str(admin_url))

with phase("Populate and save form"):
await page.get_by_role("tab", name="Steps and fields").click()

await drag_and_drop_component(page, "Radio", "group-panel-custom")
await page.get_by_test_id("input-values[0].label").fill("Label")
await page.get_by_test_id("input-values[0].value").fill("Value")
await close_modal(page, "Save")

# Save form
await page.get_by_role(
"button", name="Save and continue editing"
).click()
await page.wait_for_url(admin_url)

with phase("Validate default value"):

@sync_to_async
def assertFormValues():
configuration = (
form.formstep_set.get().form_definition.configuration
)
radio_component = configuration["components"][0]

self.assertEqual(
radio_component["defaultValue"],
"",
)

await assertFormValues()

@tag("gh-2805")
async def test_enable_translations_and_create_new_step(self):
await create_superuser()
Expand Down
9 changes: 4 additions & 5 deletions src/openforms/js/components/form/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class EmailField extends FormioEmail {
static schema(...extend) {
const schema = FormioEmail.schema(
{
defaultValue: '',
validateOn: 'blur',
},
...extend
Expand All @@ -31,12 +32,10 @@ class EmailField extends FormioEmail {
super(...args);

patchValidateDefaults(this);
}

// somewhere the default emptyValue/defaultValue does not seem to be used and it forces
// component.defaultValue to be null, which causes issues with multiples #4659
if (this.component.defaultValue === null) {
this.component.defaultValue = '';
}
get defaultSchema() {
return EmailField.schema();
}
}

Expand Down
7 changes: 1 addition & 6 deletions src/openforms/js/components/form/iban.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class IbanField extends TextField {
static schema(...extend) {
return TextField.schema(
{
defaultValue: '',
type: 'iban',
label: 'IBAN',
key: 'iban',
Expand All @@ -31,12 +32,6 @@ class IbanField extends TextField {
super(...args);

patchValidateDefaults(this);

// somewhere the default emptyValue/defaultValue does not seem to be used and it forces
// component.defaultValue to be null, which causes issues with multiples #4659
if (this.component.defaultValue === null) {
this.component.defaultValue = '';
}
}

get defaultSchema() {
Expand Down
7 changes: 1 addition & 6 deletions src/openforms/js/components/form/licenseplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class LicensePlate extends TextField {
static schema(...extend) {
const schema = TextField.schema(
{
defaultValue: '',
type: 'licenseplate',
label: 'License plate',
key: 'licenseplate',
Expand Down Expand Up @@ -39,12 +40,6 @@ class LicensePlate extends TextField {
super(...args);

patchValidateDefaults(this);

// somewhere the default emptyValue/defaultValue does not seem to be used and it forces
// component.defaultValue to be null, which causes issues with multiples #4659
if (this.component.defaultValue === null) {
this.component.defaultValue = '';
}
}

get defaultSchema() {
Expand Down
7 changes: 1 addition & 6 deletions src/openforms/js/components/form/phoneNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class PhoneNumberField extends PhoneNumber {
static schema(...extend) {
const schema = PhoneNumber.schema(
{
defaultValue: '',
inputMask: null,
},
...extend
Expand All @@ -30,12 +31,6 @@ class PhoneNumberField extends PhoneNumber {
super(...args);

patchValidateDefaults(this);

// somewhere the default emptyValue/defaultValue does not seem to be used and it forces
// component.defaultValue to be null, which causes issues with multiples #4659
if (this.component.defaultValue === null) {
this.component.defaultValue = '';
}
}

get defaultSchema() {
Expand Down
4 changes: 4 additions & 0 deletions src/openforms/js/components/form/radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class RadioField extends RadioFormio {

return super.setSelectedClasses();
}

get defaultSchema() {
return RadioField.schema();
}
}

export default RadioField;
10 changes: 3 additions & 7 deletions src/openforms/js/components/form/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const FormioTextarea = Formio.Components.components.textarea;

class TextArea extends FormioTextarea {
static schema(...extend) {
return localiseSchema(FormioTextarea.schema({validate: {maxLength: 10000}}, ...extend));
return localiseSchema(
FormioTextarea.schema({defaultValue: '', validate: {maxLength: 10000}}, ...extend)
);
}

static get builderInfo() {
Expand All @@ -23,12 +25,6 @@ class TextArea extends FormioTextarea {
super(...args);

patchValidateDefaults(this);

// somewhere the default emptyValue/defaultValue does not seem to be used and it forces
// component.defaultValue to be null, which causes issues with multiples #4659
if (this.component.defaultValue === null) {
this.component.defaultValue = '';
}
}

get defaultSchema() {
Expand Down
10 changes: 4 additions & 6 deletions src/openforms/js/components/form/textfield.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const patchValidateDefaults = instance => {

class TextField extends FormioTextField {
static schema(...extend) {
return localiseSchema(FormioTextField.schema(...extend));
return localiseSchema(FormioTextField.schema({defaultValue: ''}, ...extend));
}

static get builderInfo() {
Expand All @@ -44,12 +44,10 @@ class TextField extends FormioTextField {
super(...args);

patchValidateDefaults(this);
}

// somewhere the default emptyValue/defaultValue does not seem to be used and it forces
// component.defaultValue to be null, which causes issues with multiples #4659
if (this.component.defaultValue === null) {
this.component.defaultValue = '';
}
get defaultSchema() {
return TextField.schema();
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/openforms/js/components/form/time.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {Formio} from 'formiojs';

import {localiseSchema} from './i18n';
import {patchValidateDefaults} from './textfield';

const Time = Formio.Components.components.time;

Expand All @@ -13,12 +12,6 @@ const Time = Formio.Components.components.time;
class TimeField extends Time {
constructor(...args) {
super(...args);

// somewhere the default emptyValue/defaultValue does not seem to be used and it forces
// component.defaultValue to be null, which causes issues with multiples #4659
if (this.component.defaultValue === null) {
this.component.defaultValue = '';
}
}

static schema(...extend) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class WebformBuilder extends WebformBuilderFormio {
// using only produce seems to affect component itself, which crashes the preview
// rebuild of formio...
// const componentCopy = produce(component, draft => draft);
const componentCopy = FormioUtils.fastCloneDeep(component);
const componentCopy = {...(original || {}), ...FormioUtils.fastCloneDeep(component)};
const ComponentClass = Components.components[componentCopy.type];

// takes care of setting the defaults from the schema etc., since `component` itself
Expand Down
Loading