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

Form: fix for dateRangeBox and validation summary #25502

Merged
Merged
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
12 changes: 12 additions & 0 deletions packages/devextreme/js/ui/date_range_box/ui.date_range_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,18 @@ class DateRangeBox extends Editor {
this.getStartDateBox().focus();
}

reset() {
super.reset();

const startDateBox = this.getStartDateBox();
const endDateBox = this.getEndDateBox();

startDateBox.reset();
endDateBox.reset();
startDateBox._updateInternalValidationState(true);
endDateBox._updateInternalValidationState(true);
}

clear() {
super.clear();

Expand Down
8 changes: 4 additions & 4 deletions packages/devextreme/js/ui/form/ui.form.js
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ const Form = Widget.inherit({
this.option('isDirty', !!this._dirtyFields.size);
},

_doForAllEditors: function(editorAction) {
updateRunTimeInfoForEachEditor: function(editorAction) {
this._itemsRunTimeInfo.each(function(_, itemRunTimeInfo) {
const widgetInstance = itemRunTimeInfo.widgetInstance;
if(isDefined(widgetInstance) && Editor.isEditor(widgetInstance)) {
Expand All @@ -1162,7 +1162,7 @@ const Form = Widget.inherit({
},

_clear: function() {
this._doForAllEditors(editor => {
this.updateRunTimeInfoForEachEditor(editor => {
editor.clear();
editor.option('isValid', true);
});
Expand Down Expand Up @@ -1222,7 +1222,7 @@ const Form = Widget.inherit({
},

reset: function(editorsData) {
this._doForAllEditors(editor => {
this.updateRunTimeInfoForEachEditor(editor => {
const editorName = editor.option('name');
if(editorsData && editorName in editorsData) {
editor.reset(editorsData[editorName]);
Expand All @@ -1231,7 +1231,7 @@ const Form = Widget.inherit({
}
});

this._clearValidationSummary();
this._renderValidationSummary();
},

updateData: function(data, value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2594,6 +2594,44 @@ QUnit.module('Validation', {
assert.strictEqual(this.instance.option('isValid'), false, 'validation is failed');
});

QUnit.test('reset should clear validation', function(assert) {
this.reinit({ value: [null, null] });

this.$element.dxValidator({
validationRules: [{
type: 'required',
message: 'Both dates are required'
}]
});

const startDateBox = getStartDateBoxInstance(this.instance);
const keyboard = keyboardMock($(startDateBox.field()));

this.failInternalValidation(keyboard);

this.instance.reset();

assert.strictEqual(this.instance.option('isValid'), true);
});

QUnit.test('reset should clear input value when editor`s value hasn`t been changed', function(assert) {
const initialValue = [null, null];
this.reinit({ value: initialValue });

const startDateBox = getStartDateBoxInstance(this.instance);
const $startDateBoxInput = $(startDateBox.field());

const keyboard = keyboardMock($startDateBoxInput);
keyboard.type('123').press('enter');

assert.strictEqual($startDateBoxInput.val(), '123');
assert.deepEqual(this.instance.option('value'), initialValue);

this.instance.reset();

assert.strictEqual($startDateBoxInput.val(), '');
});

QUnit.test('dateRangeBox should not be re-validated after readOnly option change', function(assert) {
this.$element.dxValidator({
validationRules: [{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4699,4 +4699,25 @@ QUnit.module('reset', () => {

assert.strictEqual(validationItemsAfterReset.length, 0, 'form does not have validation summary items after reset');
});

QUnit.test('validation summary should appear after validating reset form', function(assert) {
const form = $('#form').dxForm({
formData: { field1: '' },
showValidationSummary: true,
items: [ {
dataField: 'field1',
validationRules: [{ type: 'required' }]
}, {
dataField: 'field2',
validationRules: [{ type: 'required' }]
} ]
}).dxForm('instance');

form.reset();
form.validate();

const summaryItemsAfterValidate = $(`.${FORM_VALIDATION_SUMMARY}`).children();

assert.strictEqual(summaryItemsAfterValidate.length, 2, 'form has validation summary after validation');
});
});
Loading