From e800e674f5b0daa4f10350b4b3e094a56c2da986 Mon Sep 17 00:00:00 2001 From: Hraban Luyat Date: Thu, 4 Jul 2024 14:45:13 -0400 Subject: [PATCH] =?UTF-8?q?feat:=20pass=20event=20and=20=E2=80=98this?= =?UTF-8?q?=E2=80=99=20to=20form=20event=20handler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also makes the handlers overridable, which makes it easier to override and/or implement new behavior. Depends on https://github.com/40ants/reblocks/pull/57 --- src/form.lisp | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/form.lisp b/src/form.lisp index 8dc4d1b..7a684fb 100644 --- a/src/form.lisp +++ b/src/form.lisp @@ -36,6 +36,9 @@ #:get-field-errors-count)) (in-package reblocks-ui/form) +(eval-when (:compile-toplevel :load-toplevel :execute) + (defvar *js-default-action* "return initiateAction(\"~A\")") + (defvar *js-default-form-action* "return initiateFormAction(\"~A\", event, this)")) (serapeum:defvar-unbound *form-field-errors* "This variable will hold a hash-table where keys are field names and values @@ -174,7 +177,7 @@ $('~A').foundation(); extra-submit-code requires-confirmation-p (confirm-question "Are you sure?") - (submit-fn "initiateFormAction(\"~A\", $(this), \"~A\")") + (submit-fn *js-default-form-action*) ;; A hashmap with placeholders widgets error-placeholders) (let* ((action (if (functionp action) @@ -230,16 +233,9 @@ $('~A').foundation(); action)) (action-code (make-action action)) (on-submit (when use-ajax-p - (format nil "~@[~A~]~A; return false;" - extra-submit-code - (format nil submit-fn - (url-encode (or action-code "")) - ;; Function session-name-string-pair was removed - ;; during reblocks refactoring, so we just - ;; - "" - ;; (reblocks::session-name-string-pair) - )))) + (concatenate 'string + (or extra-submit-code "") + (format nil submit-fn (url-encode (or action-code "")))))) (popup-name (when requires-confirmation-p (symbol-name (gensym "popup")))) @@ -364,7 +360,6 @@ $('~A').foundation(); (t confirm-question)) env)))) - (defmacro with-html-form ((method-type action &key id @@ -374,7 +369,7 @@ $('~A').foundation(); extra-submit-code requires-confirmation-p (confirm-question "Are you sure?") - (submit-fn "initiateFormAction(\"~A\", $(this), \"~A\")")) + (submit-fn *js-default-form-action*)) &body body &environment env) "Wraps a body with (:form ...) using REBLOCKS/HTML:WITH-HTML. @@ -500,8 +495,7 @@ bot, crawling the internet will hit this action with GET request." (action-code (make-action action)) (url (make-action-url action-code)) (on-click (when ajaxp - (format nil "initiateAction(\"~A\"); return false;" - action-code)))) + (format nil *js-default-action* action-code)))) (with-html (:a :id id