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

feat: pass event and ‘this’ to form event handler #10

Merged
merged 1 commit into from
Jul 29, 2024
Merged
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
24 changes: 9 additions & 15 deletions src/form.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"))))
Expand Down Expand Up @@ -364,7 +360,6 @@ $('~A').foundation();
(t confirm-question))
env))))


(defmacro with-html-form ((method-type
action &key
id
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down