File size: 1,353 Bytes
43203b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(in-package :cl-forms)

(defclass subform-form-field (form-field)
  ((subform-builder :initarg :subform-builder
                    :initform nil
                    :type (or null function)
                    :accessor field-subform-builder)
   (subform :initarg :subform
            :initform nil
            :type (or null symbol)
            :accessor field-subform-name))
  (:documentation "A field that contains a form (subform)"))

(defmethod subform-builder ((field subform-form-field))
  (or (field-subform-builder field)
      (get (field-subform-name field) :form)
      (error "Cannot build the subform in ~s" field)))

(defmethod field-subform ((field subform-form-field))
  (funcall (subform-builder field)))

(defmethod make-form-field ((field-type (eql :subform)) &rest args)
  (apply #'make-instance 'subform-form-field args))

(defmethod field-read-from-request ((field subform-form-field) form parameters)
  (let ((field-subform (field-subform field)))
    (loop for field in (form-fields field-subform)
          do (field-read-from-request (cdr field) form
                                      parameters))
      (setf (field-value field) field-subform)))

(defmethod field-add-to-path ((form-field subform-form-field) form &optional (path *field-path*))
  (cons (string-downcase (string (field-name form-field)))
         path))