If I understand the question...
Because otherwise SQLFORM would not know where to display the error.

On Oct 24, 9:52 am, TheSweetlink <yanosh...@gmail.com> wrote:
> Thank you Massimo.
>
> Because having it work isn't enough I have a question out of morbid
> curiosity/desire to learn the framework better.
>
> Why must the fieldnames match between the Field('fieldname'...)
> definition and form.errors.fieldname in my validating function in
> order to get form.errors.fieldname to flash a form error?
>
> Thank you.
>
> David
>
> On Oct 24, 10:25 am, Massimo Di Pierro <massimo.dipie...@gmail.com>
> wrote:
>
>
>
>
>
>
>
> > Good solutions. Not everything can be done with built-in validators.
>
> > On Oct 24, 12:13 am, TheSweetlink <yanosh...@gmail.com> wrote:
>
> > > Thank you all for your help.
>
> > > I was able to resolve the problem quirky as it may be but here we go.
> > > For science!!!
>
> > > To get a type='list:string' to fail validation if none passed from
> > > your SQLFORM.factory form:
>
> > > 1) Used an onvalidation=... in my form.accepts(...) /
> > > process(...).accepted / validate(...)
>
> > > Within the validation function:
>
> > > if not request.vars.choochoo:
> > >     form.errors.choochoo = "Please select 1 or more witches before
> > > burning them."
>
> > > form.errors.fieldname <--- Unless the fieldname
> > > matched .errors.fieldname, flashing form.errors.fieldname wouldn't
> > > work.
>
> > > To reiterate more simply, Field('choochoo'...) had to match
> > > form.errors.choochoo in order to have
> > > form = SQLFORM.factory(...)
> > > if form.validate(...):
> > >     do something
> > > elif form.errors.choochoo:
> > >     response.flash = form.errors.choochoo
>
> > > ^^^^work when set from my onvalidation function
>
> > > 2)  IS_NOT_EMPTY() constraint added after form = SQLFORM.factory(...)
>
> > > form.element('#no_table_myawesomeselect')
> > > ['requires']=IS_NOT_EMPTY(error_message='Please select 1 or more
> > > witches before burning them.')
>
> > > It wouldn't work when added to requires= in the Field(...) of my form
> > > = definition but only when added after form is created but before
> > > processing.
>
> > > Now my errors flash from response as they should according to the
> > > onvalidation function that's called.
>
> > > Thanks again web2py community, you're wonderful as always.
>
> > > David
>
> > > On Oct 23, 11:21 pm, ニコノコ <nikolai...@gmail.com> wrote:
>
> > > > Eeugh. Sorry for the ugly suggestion. Post validation could
>
> > > > def person_processing(form):
>
> > > > if len(form.vars.field or '')<1:
> > > >         form.errors.field= 'Select one.'
>
> > > > On Oct 24, 10:32 am, Vasile Ermicioi <elff...@gmail.com> wrote:
>
> > > > > > How about:  db.table.field.requires = IS_LENGTH(1)
>
> > > > > that will limit the field to one character, not to one value from set

Reply via email to