I've patched in the previously mentioned functionality here: http://github.com/merbjedi/dm-more
This should be a very low risk change and merge cleanly. The code changes were trivial, just need to add an additional check everywhere :allow_nil is checked for, (only about 6 places). Most of the work on this patch is done in the specs, where I've added test cases for all available allow_blank scenarios, including some missing specs on allow_nil. I also fixed up the documentation where it currently mistakenly says "allow_nil defaults to true", when in fact it defaults to false. Here' I left the functionality as is, and fixed the comments to match. Code review's welcome. I think this patch would be a huge usability improvement for Datamapper, especially for people using it for web development (majority?). On Mar 1, 1:12 pm, Jacques Crocker <[email protected]> wrote: > I'm running into this issue as well. It's turning my model code into > hell. Basically I'm nillifying any blank values on my models before > validating. Really dumb approach, but what else is there. > > I think it would be a really (really) good idea to just > use :allow_blank, similar to ActiveRecord. Seems like this would > really make DataMapper way more convenient for people dealing with > HTML forms. > > Here's a ticket for the issue. I'll post a patch > today.http://datamapper.lighthouseapp.com/projects/20609/tickets/808-valida... > > On Feb 20, 10:07 am, Stephen Eley <[email protected]> wrote: > > > Hi all, > > > Just ran into a problem with a validates_format declaration. In my > > app, e-mail addresses need to have a proper format (of course), but > > they are also optional. Despite setting :allow_nil=> true, I > > consistently get an "invalid format" error whenever I submit the form > > with the e-mail field blank. This is annoying. > > > In the code, I see that value.nil? is being checked, but I wonder if > > it should be value.blank? to properly handle the "empty string" case > > of form submissions (which is probably a lot more common than a > > missing value.) I'm about to write up a spec and submit a fix for > > this, but while I'm at it, I thought I'd ask what people think... > > > * The docs on validates_format are wrong when they say that :allow_nil > > defaults to true. It defaults to false. I personally think maybe it > > _should_ default to true: after all, if I wanted to confirm that the > > field isn't empty I'd do validates_present. Anyone disagree? I know > > that can break behavior for people who are using validates_format as > > an implied validates_present, but that's a bad idea anyway, and most > > other validations that use :allow_nilhave it defaulting to true. > > (Except validates_is_number. Should that one change as well?) > > > * Should the :allow_niloption check for .blank? instead of .nil? in > > all validators it's used in? That makes the name misleading, but I > > think it's more true to the expected behavior. > > > -- > > Have Fun, > > Steve Eley ([email protected]) > > ESCAPE POD - The Science Fiction Podcast Magazine > > http://www.escapepod.org > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "DataMapper" 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/datamapper?hl=en -~----------~----~----~----~------~----~------~--~---
