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

Editor: reset shared editors when moving between cells #1193

Closed
wants to merge 2 commits into from
Closed
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
6 changes: 6 additions & 0 deletions Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ define([

cellElement.innerHTML = '';
domClass.add(cellElement, 'dgrid-cell-editing');

// If a shared editor is being moved to a different cell reset it to clear validation state
if (cmp.domNode && cmp.domNode.parentNode !== cellElement) {
cmp.reset && cmp.reset();
}

cellElement.appendChild(cmp.domNode || cmp);

if (isWidget && !column.editOn) {
Expand Down
28 changes: 20 additions & 8 deletions test/intern/functional/Editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@ <h2>Grid with editors</h2>

<script>
var grid,
data = [
{ id: 0, name: '1', description: 'one' },
{ id: 1, name: '2', description: 'two' },
{ id: 2, name: '3', description: 'three' }
],
datachangeStack = [],
ready = false,
setEditorToTextBox;
setEditorToTextBox,
setEditorToValidationTextBox;

require([
'dojo/_base/declare',
'dgrid/Grid',
'dgrid/Editor',
'dijit/form/TextBox'
], function (declare, Grid, Editor, TextBox) {
'dijit/form/TextBox',
'dijit/form/ValidationTextBox'
], function (declare, Grid, Editor, TextBox, ValidationTextBox) {
function createColumnConfig(editorType) {
return {
id: 'ID',
Expand All @@ -48,11 +55,7 @@ <h2>Grid with editors</h2>
columns: createColumnConfig('text')
}, 'grid');

grid.renderArray([
{ id: 0, name: '1', description: 'one' },
{ id: 1, name: '2', description: 'two' },
{ id: 2, name: '3', description: 'three' }
]);
grid.renderArray(data);

// Push values received by the "dgrid-datachange" event into a global stack.
// The functional test can read from this stack to verify the values it is
Expand All @@ -65,6 +68,15 @@ <h2>Grid with editors</h2>
grid.set('columns', createColumnConfig(TextBox));
};

setEditorToValidationTextBox = function () {
var columns = createColumnConfig(ValidationTextBox);

columns.description.editorArgs = {
required: true
};
grid.set('columns', columns);
};

ready = true;
});
</script>
Expand Down
31 changes: 30 additions & 1 deletion test/intern/functional/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ define([
'require'
], function (test, assert, util, pollUntil, keys, require) {
// Number of visible rows in the grid.
// Check the data loaded in test file (editor.html) and rows visible
// Check the data loaded in test file (Editor.html) and rows visible
// when the page is loaded to ensure this is correct.
var GRID_ROW_COUNT = 3;
var rowSelectorPrefix = '#grid-row-';
Expand Down Expand Up @@ -346,5 +346,34 @@ define([

test.test('autoSave: true', createAutosaveTest());
test.test('autoSave: true - TextBox', createAutosaveTest(setTextBox));

test.test('shared editor reset', function() {
return this.remote
.get(require.toUrl('./Editor.html'))
.then(pollUntil(function () {
return window.ready;
}, null, 5000))
.execute(function () {
/* global setEditorToValidationTextBox, data */
setEditorToValidationTextBox();
data[1].description = '';
data[2].description = '';
grid.refresh();
grid.renderArray(data);
})
.findByCssSelector('#grid-row-1 .field-description')
.click()
.end()
.findByCssSelector('#grid-row-2 .field-description')
.click()
.findByCssSelector('.dijitInputInner')
.getAttribute('aria-invalid')
.then(function (isInvalid) {
assert.notStrictEqual(isInvalid, 'true',
'Cell editor validation state should not carry over into newly active cell editor');
})
.end()
.end();
});
});
});