Hi,
I've hit a roadblock trying to define validation for a view. No matter
what kind of return values I return, the thing won't work. There's no
documentation I could find, and grepping the source only turns up
examples that don't feel like working for me. So, how are per-view
validator functions meant to be used? Ie. I have the following code
(in weblocks-demo):
(defun validate-age (&rest args &key age age-field &allow-other-keys)
(setf *age-field* args)
(if (> age 10)
t
(values nil '(t t (nil . "Person is too young.") t t t t)))) ;;
here be dragons
(defview employee-form-view (:type form :inherit-from 'person-form-
view
:satisfies #'validate-age)
(company :present-as (dropdown :choices #'all-companies
:label-key #'company-name)
:parse-as (object-id :class-name 'company)
:reader (compose #'object-id #'employee-company)
:requiredp t)
(contract :present-as (radio :choices '(:full-time :part-
time :consultant :intern))
:parse-as keyword))
The current definition of VALIDATE-AGE is just the latest iteration. I
tried returning errors as (values nil "Error message"), the same with
(age . "Too young") or (nil . "Too young") in an alist, the above
(inspired by the comments in contrib/nunb/templates-crufty/template-
form-view.lisp). But each time I get:
There is no applicable method for the generic function
#<STANDARD-GENERIC-FUNCTION VIEW-FIELD-SLOT-NAME (1)>
when called with arguments
(NIL).
[Condition of type SIMPLE-ERROR]
Restarts:
[...]
Backtrace:
[...]
14: ((SB-PCL::FAST-METHOD NO-APPLICABLE-METHOD (T)) #<unavailable
argument> #<unavailable argument> #<STANDARD-GENERIC-FUNCTION VIEW-
FIELD-SLOT-NAME (1)>)[:EXTERNAL]
15: (SB-KERNEL:%ASSOC-KEY-TEST #<unavailable argument> #<unavailable
argument> #<unavailable argument> #<unavailable argument>)
16: ((SB-PCL::FAST-METHOD RENDER-VIEW-FIELD (FORM-VIEW-FIELD FORM-
VIEW T RADIO-PRESENTATION T T)) #<unavailable argument> #<unavailable
argument> #<FORM-VIEW-FIELD CONTRACT {D2233A9}> #<FORM-VIEW {CC8AE09}>
#<DATAFORM "dom7"> #<RADIO-PRESENTATION {D3A69E1}> :FULL-TIME
#<EMPLOYEE {C3FD8D9}>)[:EXTERNAL]
17: ((LAMBDA (FIELD-INFO)) #<FIELD-INFO (CONTRACT) {E5973F1}>)
18: ((LAMBDA (F-UNDERSCORE:_)) #<FIELD-INFO (CONTRACT) {E5973F1}>)
19: ((LAMBDA (WEBLOCKS::VFIELD)) #<unavailable argument>)
20: ((LABELS WEBLOCKS::MAP-LEVEL-FIELDS) #<CLOSURE (LAMBDA
(WEBLOCKS::VFIELD)) {E536275}> #<FORM-VIEW {CC8AE09}>)
21: (WEBLOCKS::%MAP-OBJECT-VIEW-FIELDS #<CLOSURE (LAMBDA (F-
UNDERSCORE:_)) {E53606D}> #<EMPLOYEE {C3FD8D9}> #<FORM-VIEW {CC8AE09}>)
[:EXTERNAL]
22: (MAP-VIEW-FIELDS #<CLOSURE (LAMBDA (FIELD-INFO)) {E535FED}>
#<FORM-VIEW {CC8AE09}> #<EMPLOYEE {C3FD8D9}>)[:EXTERNAL]
23: ((SB-PCL::FAST-METHOD WITH-VIEW-HEADER (FORM-VIEW T T T))
#<unavailable argument> #<unavailable argument> #<FORM-VIEW {CC8AE09}>
#<EMPLOYEE {C3FD8D9}> #<DATAFORM "dom7"> #<CLOSURE (SB-C::&OPTIONAL-
DISPATCH (LAMBDA #)) {E52E7CD}>)[:EXTERNAL]
24: (RENDER-OBJECT-VIEW #<EMPLOYEE {C3FD8D9}> #<FORM-VIEW {CC8AE09}>)
[:EXTERNAL]
25: ((LAMBDA (WEBLOCKS::OBJ &REST WEBLOCKS::ARGS)) #<DATAFORM
"dom7">)
26: ((SB-PCL::FAST-METHOD WITH-WIDGET-HEADER (T T)) #<unavailable
argument> #<unavailable argument> #<DATAFORM "dom7"> #<FUNCTION (SB-
C::&OPTIONAL-DISPATCH (LAMBDA #)) {BDEB585}>)[:EXTERNAL]
27: ((SB-PCL::FAST-METHOD RENDER-WIDGET (T)) #<unavailable argument>
#<unavailable argument> #<DATAFORM "dom7">)[:EXTERNAL]
[...]
I understand that I'm supposed to return a VIEW-FIELD object, but what
I don't understand is where I'm supposed to get it. The validation
function isn't given one. Also, the values returned in various tests,
such as TEST-QUICKFORM-2 (which returns (values nil (list (cons nil
"testing")))) and UPDATE-OBJECT-FROM-VIEW-5 (with (values nil "abcd"))
suggest my previous attempts should, in fact, work. I find that doubly
confusing.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"weblocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/weblocks?hl=en
-~----------~----~----~----~------~----~------~--~---