-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
feat: notify onValidationError on paste if validation failed #1462
Changes from all commits
aa4c6d0
cef417d
ec7cbb8
368c650
261c3f0
1e08359
1c04a60
0839631
7dfdb97
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { createDomElement, getHtmlStringOutput, stripTags } from '@slickgrid-universal/utils'; | ||
|
||
import type { Column, ExcelCopyBufferOption, ExternalCopyClipCommand, OnEventArgs } from '../interfaces/index'; | ||
import type { Column, Editor, ExcelCopyBufferOption, ExternalCopyClipCommand, OnEventArgs } from '../interfaces/index'; | ||
import { SlickEvent, SlickEventData, SlickEventHandler, type SlickGrid, SlickRange, type SlickDataView, Utils as SlickUtils } from '../core/index'; | ||
|
||
// using external SlickGrid JS libraries | ||
|
@@ -127,15 +127,15 @@ export class SlickCellExternalCopyManager { | |
|
||
// if a custom getter is not defined, we call serializeValue of the editor to serialize | ||
if (columnDef) { | ||
if (columnDef.editor) { | ||
if (columnDef.editorClass) { | ||
const tmpP = document.createElement('p'); | ||
const editor = new (columnDef as any).editor({ | ||
const editor = new (columnDef as any).editorClass({ | ||
container: tmpP, // a dummy container | ||
column: columnDef, | ||
event, | ||
position: { top: 0, left: 0 }, // a dummy position required by some editors | ||
grid: this._grid, | ||
}); | ||
}) as Editor; | ||
editor.loadValue(item); | ||
retVal = editor.serializeValue(); | ||
editor.destroy(); | ||
|
@@ -155,15 +155,29 @@ export class SlickCellExternalCopyManager { | |
} | ||
|
||
// if a custom setter is not defined, we call applyValue of the editor to unserialize | ||
if (columnDef.editor) { | ||
if (columnDef.editorClass) { | ||
const tmpDiv = document.createElement('div'); | ||
const editor = new (columnDef as any).editor({ | ||
const editor = new (columnDef as any).editorClass({ | ||
container: tmpDiv, // a dummy container | ||
column: columnDef, | ||
position: { top: 0, left: 0 }, // a dummy position required by some editors | ||
grid: this._grid | ||
}); | ||
}) as Editor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zewa666 ahh sorry, I missed this earlier, I think we can remove the const editor = new (columnDef.editorClass as EditorConstructor)({ })` unless this other suggestion works, which would be better const editor = new columnDef.editorClass({ }) as EditorConstructor` Note that there's 2 of these to change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure if thats gonna work as editorClass can be both the ctor and an editor according to the type There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah ok I'll take a look at that later, I wanted to check on Stackblitz but it looks like it's blocked by the VPN on work laptop, so anyway I can review that on a separate PR if it could be improved (or not) |
||
editor.loadValue(item); | ||
const validationResults = editor.validate(undefined, value); | ||
if (!validationResults.valid) { | ||
const activeCell = this._grid.getActiveCell()!; | ||
this._grid.onValidationError.notify({ | ||
editor, | ||
cellNode: this._grid.getActiveCellNode()!, | ||
validationResults, | ||
row: activeCell?.row, | ||
cell: activeCell?.cell, | ||
column: columnDef, | ||
grid: this._grid, | ||
}); | ||
} | ||
|
||
editor.applyValue(item, value); | ||
editor.destroy(); | ||
tmpDiv.remove(); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,8 @@ | |
], | ||
"types": [ | ||
"jest", | ||
"node" | ||
"node", | ||
"cypress-real-events" | ||
], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like separating external vs internal imports, so would you mind moving this import further to the top? Thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about a linter rule for that? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh does that actually exists? Dang ESLint is so powerful :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll create an additional PR after this one as it currently would involve 319 problems, pretty much all auto-fixable though ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its not only separation but also unifies blank lines between those and ordered imports. So with the extra PR you get a chance to tweak those configs as you prefer.
I'll set it up tomorrow as I need to get some rest today