hi Kenny,
My idea is to validate your form with formencode.Schema, This is a
peace of code that work for me :
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):
.... and your code ...
But, for me validators should check any case of user entry, so this
one should be the best in you case in my mind :
from formencode.foreach import ForEach
from formencode.validators import OneOf
from formencode import Schema
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.