From 8c659c991bdbc63b93fd8f04ca72e46b020b09a2 Mon Sep 17 00:00:00 2001 From: Ghislain B Date: Wed, 17 Jan 2024 00:27:28 -0500 Subject: [PATCH] fix: when `onResizeStart` return false it should stop (#978) - when `onResizeStart` returns `false`, for example when editor `commitCurrentEdit()` fails, then the column resize shouldn't be allowed --- examples/example4-model-esm.html | 4 +++- src/slick.interactions.ts | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/examples/example4-model-esm.html b/examples/example4-model-esm.html index c01fde24..40902015 100644 --- a/examples/example4-model-esm.html +++ b/examples/example4-model-esm.html @@ -222,7 +222,9 @@

View Source:

function requiredFieldValidator(value) { if (value == null || value == undefined || !value.length) { - return {valid: false, msg: "This is a required field"}; + return {valid: false, msg: 'This is a required field'}; + } else if (!/^(task\s\d+)*$/i.test(value)) { + return { valid: false, msg: 'Your title is invalid, it must start with "Task" followed by a number.' }; } else { return {valid: true, msg: null}; diff --git a/src/slick.interactions.ts b/src/slick.interactions.ts index cb72a272..2658dbf6 100644 --- a/src/slick.interactions.ts +++ b/src/slick.interactions.ts @@ -231,18 +231,20 @@ export function Resizable(options: ResizableOption) { function executeResizeCallbackWhenDefined(callback?: Function, e?: MouseEvent | TouchEvent | Touch) { if (typeof callback === 'function') { - callback(e, { resizeableElement, resizeableHandleElement }); + return callback(e, { resizeableElement, resizeableHandleElement }); } } function resizeStartHandler(e: MouseEvent | TouchEvent) { e.preventDefault(); const event = (e as TouchEvent).touches ? (e as TouchEvent).changedTouches[0] : e; - executeResizeCallbackWhenDefined(onResizeStart, event); - document.body.addEventListener('mousemove', resizingHandler); - document.body.addEventListener('mouseup', resizeEndHandler); - document.body.addEventListener('touchmove', resizingHandler); - document.body.addEventListener('touchend', resizeEndHandler); + const result = executeResizeCallbackWhenDefined(onResizeStart, event); + if (result !== false) { + document.body.addEventListener('mousemove', resizingHandler); + document.body.addEventListener('mouseup', resizeEndHandler); + document.body.addEventListener('touchmove', resizingHandler); + document.body.addEventListener('touchend', resizeEndHandler); + } } function resizingHandler(e: MouseEvent | TouchEvent) {