Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1033 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

validation isn't working as expected in MultipleSelectField

Reported by: jerojasro Owned by: anonymous
Priority: normal Milestone: 0.9a7
Component: TG Widgets Version: 0.9a6
Severity: normal Keywords: widget validator
Cc:

Description

the validator that I pass to the MultipleSelectField? is "applied" only to the elements of the list that I get when submitting the form, not to the list itself. Due to this, I can't make that a validator forces the user to select al least one value. When no values are selected in the form, the validator doesn't even get called (!)

a lot of info (I hope) can be found in a thread of the tg group

http://groups.google.com/group/turbogears/browse_thread/thread/7d36c2beafa96394

Attachments

forms.tar.gz Download (19.4 KB) - added by jerojasro 13 years ago.
a minimum tg project with the problem stated. It should start the server with no problems
working-forms.tar.gz Download (15.7 KB) - added by alberto 13 years ago.

Change History

Changed 13 years ago by jerojasro

a minimum tg project with the problem stated. It should start the server with no problems

comment:1 Changed 13 years ago by alberto

  • Status changed from new to closed
  • Resolution set to fixed

Please try teh 1.0 branch since [1651] see if it solves your use-case. I'm attaching a modified version of forms.tar.gz to show how it can be done.

The problem is (was) that the the MultipleSelectionField? builds it's own ForEach? validator based on the one provided. The ForEach? validator is the one in charge of validating the list as a whole which is the only moment we can see how many items are actually selected.

The proposed solution is to avoid this validatior-building if you provide your own validator which *must* subclass validators.ForEach?. Just don't forget to initialize your ForEach? subclass with the correct validator to validate the list's items (in your case, an Int)

HTH, Alberto

P.S Please reopen if I missed something.

Changed 13 years ago by alberto

Note: See TracTickets for help on using tickets.