Hi,
the proposed solution kind of works. It now indeed gives the message
that a field is empty, but unfortunately also resets the form.
I don't know if this is the result of populating the form from a DB, I
didn't really look into it.
But this seems to work as expected:
# -*- coding: utf-8 -*-
""" root form: form on the first page """
from tw.api import WidgetsList
from formencode.api import NoDefault
from tw.forms import TableForm, MultipleSelectField, CheckBoxTable
from tw.forms.validators import Int, ForEach, OneOf
class RootForm(TableForm):
class fields(WidgetsList):
annotation_options = [u'transcripts', u'genes', u'proteins']
types = MultipleSelectField(
label_text = 'Type',
help_text = 'Please select one or more experiment types',
validator = ForEach(Int, if_missing=NoDefault)
)
annotations = CheckBoxTable(
options = annotation_options,
label_text = 'Annotations',
help_text = 'Please select one or more of the annotation
types',
validator = ForEach(OneOf(annotation_options),
if_missing=NoDefault)
)
timepoints = CheckBoxTable(
label_text = 'Timepoints',
help_text = 'Please select timepoints',
validator = ForEach(Int, if_missing=NoDefault)
)
submit_text = 'Go!'
hover_help = True
show_errors = True
action = 'overview'
root_form = RootForm('root_form')
Thx for the hint,
Kenny
On Jan 5, 9:57 pm, BeeBob <[email protected]> wrote:
> Hi Kenny,
>
> My idea is to use formencode.Schema to validate your form.
>
> from tw.forms.validators import NotEmpty,
> from formencode import Schema
>
> class ValidateAnswer(Schema):
> filter_extra_fields = True
> allow_extra_fields = True
> annotations_widget= NotEmpty
>
> class RootForm(TableForm):
> validator = ValidateAnswer
> class fields(WidgetsList):
> value_types_widget = MultipleSelectField(..
> ....
>
> In another hand, the aim form validators is to check all possible case
> so, for me the best way is following
>
> from formencode import Schema
> from formencode.foreach import ForEach
> from formencode.validators import OneOf
>
> class ValidateAnswerBest(Schema):
> filter_extra_fields = True
> allow_extra_fields = True
> AvailableOptions = ['transcripts', 'genes', 'proteins']
> annotations_widget= All(chained_validators=[ NotEmpty,
> ForEach(OneOf(AvailableOptions)) ])
>
> Regards.
>
> On 4 jan, 18:46, Kenny <[email protected]> wrote:
>
> > Hey all,
>
> > I'm trying to get validation working on MultipleSelectField and
> > CheckBoxLists and CheckBoxTables.
>
> > This is the widget form created:
>
> > # -*- coding: utf-8 -*-
> > """ root form: form on the first page """
>
> > from tw.api import WidgetsList
> > from tw.forms import TableForm, MultipleSelectField, CheckBoxList,
> > CheckBoxTable, InputField
> > from tw.forms.validators import Set, Empty, NotEmpty, Int
>
> > class RootForm(TableForm):
>
> > class fields(WidgetsList):
> > value_types_widget = MultipleSelectField(
> > label_text = 'Type',
> > help_text = 'Please select one or more experiment types',
> > validator = Set(not_empty=True)
> > )
> > annotations_widget = CheckBoxTable(
> > options = ['transcripts', 'genes', 'proteins'],
> > label_text = 'Annotation',
> > help_text = 'Please select one or more of the annotation
> > types',
> > validator = NotEmpty
> > )
> > timepoints_widget = CheckBoxTable(
> > label_text = 'Timepoints',
> > help_text = 'Please select timepoints',
> > validator = Int(not_empty=True)
> > )
> > #test_widget = InputField( validator = NotEmpty)
>
> > submit_text = 'Go!'
> > hover_help = True
> > show_errors = True
> > action = 'overview'
>
> > root_form = RootForm('root_form')
>
> > The only validation I want to do is make sure something is ticked or
> > selected, but none of the above methods really work. Also changing the
> > validator to Set, Set(non_empty=True) or leaving out the not_empty
> > param doesn't change anything.
> > If not commented out, the test_widget works as expected and displays
> > an error saying the input box cannot be empty.
>
> > I am using
> > tg2.1
> > tw.forms 0.9.9
> > ToscaWidgets 0.9.10
> > FormEncode 1.2.2
>
> > Any suggestions?
>
> > Kenny
--
You received this message because you are subscribed to the Google Groups
"TurboGears" 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/turbogears?hl=en.