Paste number 24174: how to differentiate between two submit buttons ?

Index of paste annotations: 1 | 2 | 3

Paste number 24174: how to differentiate between two submit buttons ?
Pasted by: dmgenp
When:18 years, 6 months ago
Share:Tweet this! | http://paste.lisp.org/+INI
Channel:#ucw
Paste contents:
Raw Source | XML | Display As
suppose i want a page with a bunch of fields, and two buttons, ok an apply. if user push apply, form contents just sent into db, but if user click ok, he also redirected to previous page.

how can i check which button user clicked ? (value (ok-button test)) always returns empty string.

example code:

(defcomponent test (widget-component)
  ((field :accessor field :initform (make-instance 'string-field))
   (apply-button :accessor apply-button
		 :initform (make-instance 'submit-button :label "Apply"))
   (ok-button :accessor ok-button
	      :initform (make-instance 'submit-button :label "OK")))
  (:render ()
	   (<:div (<ucw:form :action (progn
				       (update-some-db :field (field test))
				       (if (value (ok-button test))
					 (return-to-upper-level)))
		    (render (field test))
		    (render (apply-button test))
		    (render (ok-button test))))))



Annotations for this paste:

Annotation number 1: <ucw:submit :action doesn't work within <ucw:form
Pasted by: dmgenp
When:18 years, 6 months ago
Share:Tweet this! | http://paste.lisp.org/+INI/1
Paste contents:
Raw Source | Display As
if i try to use <ucw:submit :action (setf (button-clicked test) t),
this action does not execute, ucw:form's :action executed instead.
if i remove ucw:form's :action, nothing executes at all on submit.

Annotation number 2: redefining render on submit-button to get a value when it's pressed
Pasted by: dmgenp
When:18 years, 6 months ago
Share:Tweet this! | http://paste.lisp.org/+INI/2
Paste contents:
Raw Source | Display As
(defmethod render ((field submit-button))
  (<ucw:submit :id (dom-id field)
	       :accesskey (accesskey field)
	       :name (name field)
	       :title (tooltip field)
	       :tabindex (tabindex field)
	       :writer (lambda (v)
			 (setf (client-value field) v))
	       :reader (label field)
	       :class (css-class field)
	       :style (css-style field)))

Annotation number 3: probably, adding (:default-initargs :client-value nil) to defclass submit-button will be convenient, too
Pasted by: dmgenp
When:18 years, 6 months ago
Share:Tweet this! | http://paste.lisp.org/+INI/3
Paste contents:
Raw Source | Display As
(defclass submit-button (generic-html-input)
  ((label :accessor label :initform nil :initarg :label))
  (:default-initargs :client-value nil))

Colorize as:
Show Line Numbers

Lisppaste pastes can be made by anyone at any time. Imagine a fearsomely comprehensive disclaimer of liability. Now fear, comprehensively.