unique id per instance with generated code

This commit is contained in:
David Botton 2022-01-26 18:43:52 -05:00
parent e78864a6af
commit 83fa7e7f00
2 changed files with 18 additions and 8 deletions

View file

@ -40,7 +40,7 @@ clog[] but is not in the DOM. If HTML-ID is nil one is generated.
(private)"
(let ((web-id (if html-id
html-id
(clog-connection:generate-id))))
(format nil "CLOG~A" (clog-connection:generate-id)))))
(clog-connection:execute
connection-id
(format nil
@ -86,15 +86,24 @@ CLOG-OBJ. If HTML-ID is nil one will be generated."))
;; attach-as-child ;;
;;;;;;;;;;;;;;;;;;;;;
(defgeneric attach-as-child (clog-obj html-id &key clog-type)
(:documentation "Create a new CLOG-Element or sub-type of CLOG-TYPE and
(defgeneric attach-as-child (clog-obj html-id &key clog-type new-id)
(:documentation "Create a new CLOG-ELEMENT or sub-type of CLOG-TYPE and
attach an existing element with HTML-ID. The HTML-ID must be unique and
must be in DOM, ie placed or auto-placed."))
must be in DOM, ie placed or auto-placed. If new-id is true the HTML-ID
after attachment is changed to one unique to this session."))
(defmethod attach-as-child ((obj clog-obj) html-id
&key (clog-type 'clog-element))
&key (clog-type 'clog-element)
(new-id nil))
(if new-id
(let ((id (format nil "CLOG~A" (clog-connection:generate-id))))
(clog-connection:execute (connection-id obj)
(format nil "clog['~A']=$('#~A').get(0)" html-id html-id))
(format nil "$('#~A').attr('id','~A');clog['~A']=$('#~A').get(0)"
html-id id id id))
(setf html-id id))
(clog-connection:execute (connection-id obj)
(format nil "clog['~A']=$('#~A').get(0)"
html-id html-id)))
(make-clog-element (connection-id obj) html-id :clog-type clog-type))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View file

@ -778,7 +778,8 @@ of controls and double click to select control."
vname)
cmembers)
(push (format nil
"\(setf (slot-value panel '~A\) \(attach-as-child clog-obj \"~A\" :clog-type \'~A\)\)~%"
"\(setf (slot-value panel '~A\) ~
\(attach-as-child clog-obj \"~A\" :clog-type \'~A\ :new-id t)\)~%"
vname
html-id
(format nil "CLOG:~A" (type-of control)))