Skip to content

Commit

Permalink
feat: pass event and ‘this’ to form event handler
Browse files Browse the repository at this point in the history
Also makes the handlers overridable, which makes it easier to override and/or
implement new behavior.

Depends on 40ants/reblocks#57
  • Loading branch information
hraban committed Jul 4, 2024
1 parent b35f364 commit e800e67
Showing 1 changed file with 9 additions and 15 deletions.
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

0 comments on commit e800e67

Please sign in to comment.