changed create-form-element to accept additional keywords.

This commit is contained in:
ormf 2023-07-22 18:11:44 +02:00
parent 6302deb6e6
commit f518a9b1c8

View file

@ -204,24 +204,29 @@ elements."))
:file :hidden :image :month :number :password :radio :range :file :hidden :image :month :number :password :radio :range
:reset :search :submit :tel :text :time :url :week)) :reset :search :submit :tel :text :time :url :week))
(defgeneric create-form-element (clog-obj element-type (defgeneric create-form-element (clog-obj element-type &rest args
&key name value label class &key name class style hidden html-id auto-place label
style hidden html-id auto-place) &allow-other-keys)
(:documentation "Create a new clog-form-element as child of CLOG-OBJ. (:documentation "Create a new clog-form-element as child of CLOG-OBJ.
It is importamt that clog-form-elements are a child or descendant of a It is importamt that clog-form-elements are a child or descendant of a
clog-form in the DOM. The radio ELEMENT-TYPE groups by NAME.")) clog-form in the DOM. The radio ELEMENT-TYPE groups by
NAME. Additional keys will be added to the input tag as
attribute/value pairs in the form attr= 'value'"))
(defmethod create-form-element ((obj clog-obj) element-type (defmethod create-form-element ((obj clog-obj) element-type &rest args
&key (name nil) &key (name nil)
(value nil)
(label nil) (label nil)
(class nil) (class nil)
(style nil) (style nil)
(hidden nil) (hidden nil)
(html-id nil) (html-id nil)
(auto-place t)) (auto-place t))
(let ((element (create-child (declare (ignorable name value min max))
obj (format nil "<input type='~A'~@[~A~]~@[~A~]~@[~A~]~@[~A~]/>" (dolist (key '(name class style hidden html-id auto-place))
(remf args key))
(let* (
(element (create-child
obj (format nil "<input type='~A'~@[~A~]~@[~A~]~{~(~A~)= '~A'~^ ~}/>"
(escape-string element-type :html t) (escape-string element-type :html t)
(when class (when class
(format nil " class='~A'" (format nil " class='~A'"
@ -230,8 +235,7 @@ clog-form in the DOM. The radio ELEMENT-TYPE groups by NAME."))
(format nil " style='~@[~a~]~@[~a~]'" (format nil " style='~@[~a~]~@[~a~]'"
(when hidden "visibility:hidden;") (when hidden "visibility:hidden;")
style)) style))
(when value (format nil " value='~A'" (escape-string value :html t))) args)
(when name (format nil " name='~A'" (escape-string name :html t))))
:clog-type 'clog-form-element :clog-type 'clog-form-element
:html-id html-id :html-id html-id
:auto-place auto-place))) :auto-place auto-place)))