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,37 +204,41 @@ 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))
(escape-string element-type :html t) (remf args key))
(when class (let* (
(format nil " class='~A'" (element (create-child
(escape-string class :html t))) obj (format nil "<input type='~A'~@[~A~]~@[~A~]~{~(~A~)= '~A'~^ ~}/>"
(when (or hidden style) (escape-string element-type :html t)
(format nil " style='~@[~a~]~@[~a~]'" (when class
(when hidden "visibility:hidden;") (format nil " class='~A'"
style)) (escape-string class :html t)))
(when value (format nil " value='~A'" (escape-string value :html t))) (when (or hidden style)
(when name (format nil " name='~A'" (escape-string name :html t)))) (format nil " style='~@[~a~]~@[~a~]'"
:clog-type 'clog-form-element (when hidden "visibility:hidden;")
:html-id html-id style))
:auto-place auto-place))) args)
:clog-type 'clog-form-element
:html-id html-id
:auto-place auto-place)))
(when label (when label
(label-for label element)) (label-for label element))
element)) element))