From 4a92ce256a4158db41e23fdfeda37e7edfa032a3 Mon Sep 17 00:00:00 2001 From: Sabra Crolleton Date: Mon, 2 Oct 2023 10:32:25 -0400 Subject: [PATCH] Give form-dialog textarea capability Adds generic function textarea-value in clog-form.lisp Exports textarea-value in clog.lisp Adds the option into form-dialog in clog-gui.lisp, with additional key parameters for size and rows and adds it to the list of special field types in the doc string. --- source/clog-form.lisp | 12 ++++++++ source/clog-gui.lisp | 65 ++++++++++++++++++++++++++++--------------- source/clog.lisp | 1 + 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/source/clog-form.lisp b/source/clog-form.lisp index 7b5f7ba..80bd600 100644 --- a/source/clog-form.lisp +++ b/source/clog-form.lisp @@ -465,6 +465,18 @@ be unique name on entire document.")) (clog-connection:query (connection-id obj) (format nil "$('select[name=~A] option:selected').val()" name))) +;;;;;;;;;;;;;;;; +;; textarea-value ;; +;;;;;;;;;;;;;;;; + +(defgeneric textarea-value (clog-obj name) + (:documentation "Returns the value of textarea item called NAME and must +be unique name on entire document.")) + +(defmethod textarea-value ((obj clog-obj) name) + (clog-connection:query (clog::connection-id obj) + (format nil "$('textarea#~A').val()" name))) + ;;;;;;;;;;;;;;;; ;; name-value ;; ;;;;;;;;;;;;;;;; diff --git a/source/clog-gui.lisp b/source/clog-gui.lisp index c9eb165..9b11b5d 100644 --- a/source/clog-gui.lisp +++ b/source/clog-gui.lisp @@ -1614,6 +1614,7 @@ Calls on-input with t if confirmed or nil if canceled." (cancel-text "Cancel") (left nil) (top nil) (width 400) (height 500) + (size 40) (rows 4) (client-movement nil) (html-id nil)) "Create a form dialog box with CONTENT followed by FIELDS. @@ -1632,10 +1633,13 @@ Special field types :checkbox t if checked :radiobox a-list ((label name)) a third value can be added \"checked\" :select a-list ((label name)) a third value can be added \"selected\" + :textarea value :text value (any text input types also work :email, :tel, etc. see FORM-ELEMENT-TYPE) +The size of any texarea field is controled by the size and rows parameters + Calls on-input after OK or Cancel with an a-list of field name to value if confirmed or nil if canceled." (unless html-id @@ -1666,17 +1670,17 @@ if confirmed or nil if canceled." (format nil "~{~A~}" (mapcar (lambda (s) (format nil - "
~
" - html-id (second l) - html-id (second l) (second s) - (second s) - (if (third s) - (third s) - "") - html-id (second l) (second s) - (first s))) + html-id (second l) + html-id (second l) (second s) + (second s) + (if (third s) + (third s) + "") + html-id (second l) (second s) + (first s))) (fourth l))))) ((eq (third l) :checkbox) (format nil @@ -1691,26 +1695,41 @@ if confirmed or nil if canceled." "") html-id (second l) (first l))) + ((eq (third l) :textarea) + (format nil + "
+
" + (first l) + html-id + (second l) + html-id + (second l) + size + rows + (if (fourth l) + (fourth l) + ""))) ((third l) (format nil "
~
" - (first l) (third l) - html-id (second l) html-id (second l) - (if (fourth l) - (fourth l) - ""))) + (first l) (third l) + html-id (second l) html-id (second l) + (if (fourth l) + (fourth l) + ""))) (t (format nil - "
~ + "
~
" - (first l) html-id (second l) html-id (second l))))) + (first l) html-id (second l) html-id (second l))))) fields))) (win (create-gui-window obj :title title :content (format nil -"
+ "
~A
~A @@ -1722,9 +1741,9 @@ if confirmed or nil if canceled."
" (if content (format nil "
~A

" content) "") - fls - html-id ok-text ; ok - html-id cancel-text) ; cancel + fls + html-id ok-text ; ok + html-id cancel-text) ; cancel :top top :left left :width width @@ -1746,8 +1765,8 @@ if confirmed or nil if canceled." (mapcar (lambda (l) (when (eq (third l) :filename) (let ((fld (attach-as-child body (format nil "~A-~A" - html-id - (second l)) + html-id + (second l)) :clog-type 'clog:clog-form-element))) (set-on-click fld (lambda (obj) (declare (ignore obj)) @@ -1777,6 +1796,8 @@ if confirmed or nil if canceled." (radio-value win name)) ((eq (third l) :checkbox) (checkbox-value win name)) + ((eq (third l) :textarea) + (textarea-value win name)) (t (name-value win name)))))) fields))) diff --git a/source/clog.lisp b/source/clog.lisp index b41acb3..4046e1d 100644 --- a/source/clog.lisp +++ b/source/clog.lisp @@ -690,6 +690,7 @@ embedded in a native template application.)" (radio-value generic-function) (checkbox-value generic-function) (select-value generic-function) + (textarea-value generic-function) (name-value generic-function) (pattern generic-function) (minimum generic-function)