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 #659 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

SelectionFields with Int validators don't like no values

Reported by: xentac Owned by: anonymous
Priority: normal Milestone:
Component: TG Widgets Version:
Severity: critical Keywords:
Cc:

Description

If you create a CheckBoxList? that uses a Int validator (by making sure all the options you pass in have integer values), you'll get an error trying to submit a form with nothing checked.

Apparently, formencode's ForEach? has convert_to_list set, so a blank string is converted to [], and then is passed to the int validator and it doesn't accept it.

I couldn't find an unugly or straigtforward way to fix this... I ended up creating my own validator like this:

self.validator = formencode.ForEach?(convert_to_list=False, if_empty=[]) self.validator.validators = [validators.Int()]

The problem with this is that if there is nothing checked, the variable passed to my method (data, because I'm using the fast data controller) on form submit, doesn't exist.

Change History

comment:1 Changed 13 years ago by michele

I will look into this late today or tomorrow.

comment:2 Changed 13 years ago by michele

Can you try with the latest svn Jason?

comment:3 Changed 13 years ago by xentac

It works now. It's perfect.

comment:4 Changed 13 years ago by anonymous

  • Status changed from new to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.