rabbibotton / clog

CLOG - The Common Lisp Omnificent GUI
Other
1.49k stars 102 forks source link

link-form-element-to-slot fails with non-default :set-event arguments #187

Closed mikelevins closed 2 years ago

mikelevins commented 2 years ago

Steps to reproduce:

  1. Implement a create-main-page that uses create-child to construct a DOM subtree from HTML. Include an element in the HTML. change-class the clog-obj to a class that contains a slot to which you can link a form element.
  2. Use attach-as-child to fetch a reference to the element by HTML ID (making sure to use :clog-type 'clog-form-element).
  3. Call link-form-element-to-slot to link the to the slot.

Expected result: Editing the contents of the element updates the corresponding linked slot.

Found result: If the default :set-event value is used, or if the default (clog:set-on-change) is explicitly passed then the slot is updated as expected. If any other set-on-* is passed for :set-event, then triggering it yields a SIMPLE-PROGRAM-ERROR with message "invalid number of arguments: 2".

rabbibotton commented 2 years ago

It works for events that there is no associated data parameter. Like on-click - (mod of tutorial 29)

    (link-form-element-to-slot i3 lisp-obj my-count
                               :set-event #'clog:set-on-click
                               :transform #'parse-integer)

so the count changes when the input is clicked as opposed to losing focus.

You could wrap it like so:

    (link-form-element-to-slot i3 lisp-obj my-count
                               :set-event (lambda (clog-obj handler)
                                            (set-on-key-down clog-obj
                                                             (lambda (obj data)
                                                               (funcall handler obj))))
                               :transform #'parse-integer)

This also allows for you to not fire the event unless say the data is valid etc.

I will try and add some more documentation.