|
From: Ian B. <ia...@co...> - 2005-07-12 17:04:45
|
Kazansky, Stella (SKAZANSK) wrote: > Ian, > We are using formencode package to validate our forms created usin > ZPTKit templates. > The question is: based on the exaples I saw the validators for the > fields have to match the field names in the form, like: > title = validators.String(not_empty=True) where "title" is a form > element name. > In my case the field name is created dynamically based on the data > passed in the request. > How can I validate such a field? Well, it depends on why you are creating the field names dynamically. If it's because of repeating field names, you can use the fieldname-number notation, and use the ForEach validator (which will apply its sub-validator to each set of fields based on the number). If it's because you are encoding multiple pieces of data to go together (e.g., article ID encoded into field name, article title as field content) then you can turn that into two fields with an arbitrary number, e.g., article-N.id: a hidden field with the article ID; article-N.title: the text field with the accompanying title. -- Ian Bicking / ia...@co... / http://blog.ianbicking.org |