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

FIO-7937/FIO-7953: Fixes issues where Reset action does not clear values and restore the default ones #5939

Open
wants to merge 2 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
7 changes: 7 additions & 0 deletions src/components/_classes/component/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2964,12 +2964,19 @@
this.setValueAt(i, isArray && !this.isSingleInputValue() ? value[i] : value, flags);
}
}

// Also reset value of the modal component, otherwise it will keep the old value locally and the preview
// element won't refresh
if (this.componentModal && flags && flags.resetValue) {
this.componentModal.setValue(value);
}

return changed;
}

/**
* Returns if the value (e.g. array) should be divided between several inputs
* @returns {boolean}

Check warning on line 2979 in src/components/_classes/component/Component.js

View workflow job for this annotation

GitHub Actions / setup

Missing JSDoc @returns description
*/
isSingleInputValue() {
return false;
Expand Down
4 changes: 3 additions & 1 deletion src/components/_classes/nested/NestedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,10 @@ export default class NestedComponent extends Field {
}

resetValue() {
super.resetValue();
// Reset values of child components first, then reset the parent one, otherwise it will restore the default
// value of parent component and clear it one by one while resetting child components
this.getComponents().forEach((comp) => comp.resetValue());
super.resetValue();
this.setPristine(true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/address/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export default class AddressComponent extends ContainerComponent {
this.restoreComponentsContext();
}

if (changed || !_.isEmpty(value) && flags.fromSubmission) {
if (changed || !_.isEmpty(value) && flags.fromSubmission || flags.resetValue) {
this.redraw();
}

Expand Down
10 changes: 0 additions & 10 deletions src/components/editgrid/EditGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -1409,16 +1409,6 @@ export default class EditGridComponent extends NestedArrayComponent {
this.setNestedValue(component, editRow.data, flags);
});
}

emptyRows() {
this.editRows.forEach((editRow, index) => this.destroyComponents(false, index));
this.editRows = [];
}

resetValue() {
super.resetValue();
this.emptyRows();
}
}

EditGridComponent.prototype.hasChanged = Component.prototype.hasChanged;
8 changes: 4 additions & 4 deletions src/components/radio/Radio.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,15 @@ export default class RadioComponent extends ListComponent {
return defaultValue;
}

resetValue() {
uncheckValue(flags = {}) {
this.unset();
this.setValue(this.emptyValue, {
noUpdateEvent: true,
noValidate: true,
resetValue: true
});
this.triggerChange(flags);
this.setSelectedClasses();
}

get inputInfo() {
Expand Down Expand Up @@ -459,9 +461,7 @@ export default class RadioComponent extends ListComponent {
this.currentValue = this.dataValue;
const shouldResetValue = flags && flags.modified && !flags.noUpdateEvent && this.previousValue === this.currentValue;
if (shouldResetValue) {
this.resetValue();
this.triggerChange(flags);
this.setSelectedClasses();
this.uncheckValue(flags);
}
this.previousValue = this.dataValue;
return changed;
Expand Down
2 changes: 1 addition & 1 deletion src/components/selectboxes/SelectBoxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export default class SelectBoxesComponent extends RadioComponent {
return super.setCustomValidity(_.filter(messages, (message) => message.ruleName !=='invalidValueProperty'), dirty, external);
} else {
return super.setCustomValidity(messages, dirty, external);
};
}
}

validateValueAvailability(setting, value) {
Expand Down
187 changes: 187 additions & 0 deletions test/forms/resetActionDefaultValueBasicComponents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
export default {
"title": "Basic",
"type": "form",
"name": "basic",
"path": "basic",
"display": "form",
"components": [
{
"label": "Text Field - populate",
"applyMaskOn": "change",
"tableView": true,
"key": "textFieldPopulate",
"type": "textfield",
"input": true,
"defaultValue": "12345"
},
{
"label": "Number - populate",
"applyMaskOn": "change",
"mask": false,
"tableView": false,
"delimiter": false,
"requireDecimal": false,
"inputFormat": "plain",
"truncateMultipleSpaces": false,
"key": "numberPopulate",
"type": "number",
"input": true,
"defaultValue": 25
},
{
"label": "Text Field",
"applyMaskOn": "change",
"tableView": true,
"customDefaultValue": "value = data.textFieldPopulate + \"new\";",
"key": "textField",
"type": "textfield",
"input": true
},
{
"label": "Text Area",
"applyMaskOn": "change",
"autoExpand": false,
"tableView": true,
"customDefaultValue": "value = data.textFieldPopulate + \"new1\";",
"key": "textArea",
"type": "textarea",
"input": true
},
{
"label": "Number",
"applyMaskOn": "change",
"mask": false,
"tableView": false,
"delimiter": false,
"requireDecimal": false,
"inputFormat": "plain",
"truncateMultipleSpaces": false,
"customDefaultValue": "value = data.numberPopulate + 25",
"key": "number",
"type": "number",
"input": true
},
{
"label": "Checkbox",
"tableView": false,
"defaultValue": false,
"customDefaultValue": "value = true",
"key": "checkbox",
"type": "checkbox",
"input": true
},
{
"label": "Select Boxes",
"optionsLabelPosition": "right",
"tableView": false,
"defaultValue": {
"1": false,
"2": false,
"3": false
},
"values": [
{
"label": "one",
"value": "1",
"shortcut": ""
},
{
"label": "two",
"value": "2",
"shortcut": ""
},
{
"label": "three",
"value": "3",
"shortcut": ""
}
],
"customDefaultValue": "value = {\n \"1\": true,\n \"2\": false,\n \"3\": true\n }",
"key": "selectBoxes",
"type": "selectboxes",
"input": true,
"inputType": "checkbox"
},
{
"label": "Select",
"widget": "choicesjs",
"tableView": true,
"data": {
"values": [
{
"label": "one",
"value": "1"
},
{
"label": "two",
"value": "2"
},
{
"label": "three",
"value": "3"
}
]
},
"customDefaultValue": "value = 1",
"key": "select",
"type": "select",
"input": true
},
{
"label": "Radio",
"optionsLabelPosition": "right",
"inline": false,
"tableView": false,
"values": [
{
"label": "one",
"value": "1",
"shortcut": ""
},
{
"label": "two",
"value": "2",
"shortcut": ""
},
{
"label": "three",
"value": "3",
"shortcut": ""
}
],
"customDefaultValue": "value = 2",
"key": "radio",
"type": "radio",
"input": true
},
{
"label": "Reset",
"action": "reset",
"showValidations": false,
"theme": "danger",
"tableView": false,
"key": "reset",
"type": "button",
"input": true
},
{
"label": "Reset custom",
"action": "custom",
"showValidations": false,
"theme": "secondary",
"tableView": false,
"key": "resetCustom",
"type": "button",
"custom": "instance.emit('resetForm')",
"input": true
},
{
"type": "button",
"label": "Submit",
"key": "submit",
"disableOnInvalid": true,
"input": true,
"tableView": false
}
]
};
Loading
Loading