Skip to content

Commit

Permalink
Editor: Reset shared validation editors when moving between cells
Browse files Browse the repository at this point in the history
Includes new functional test for validation state of shared editors.

(cherry picked from commit 80101c6)
  • Loading branch information
msssk authored and Kenneth G. Franqueiro committed Jan 5, 2016
1 parent ecc1f8a commit d4f9d5a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,12 @@ define([
put(cellElement, '.dgrid-cell-editing');
put(cellElement, cmp.domNode || cmp);

// If a shared editor is a validation widget, reset it to clear validation state
// (The value will be preserved since it is explicitly set in _startupEditor)
if (isWidget && column.editOn && cmp.validate && cmp.reset) {
cmp.reset();
}

if (isWidget && !column.editOn) {
// Queue arguments to be run once editor is in DOM
this._editorsPendingStartup.push([cmp, column, cellElement, value]);
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 @@ -18,16 +18,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 @@ -47,11 +54,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 @@ -64,6 +67,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.get('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();
});
});
});

0 comments on commit d4f9d5a

Please sign in to comment.