brockpetrie / dynamictextgroup

A Symphony field that provides a method to dynamically add a text field or text field groups to a section entry
22 stars 13 forks source link

Numeric validation errors on use of Zero "0" #4

Closed andrewminton closed 13 years ago

andrewminton commented 13 years ago

Hi Brock,

Been playing a bit more and discovered that if my field is a required field and I set the validation of a field to numeric, I can't save the section due to "0" not being validated as a number.

Basically, trying to build a Quiz and have all fields with no value have a count of zero. If it's a positive value, all is well.

I'm not too hot on regex so woudln't know where to begin there.

Is this something you've encountered yet?

brockpetrie commented 13 years ago

Good catch. PHP likes to treat the number zero as representing an empty value. This will fix it:

Edit line 370 of fields/field.dynamictextgroup.php that says if (!empty($field[$i])) {

Change it to: if (!empty($field[$i]) || $field[$i] == '0') {

I'll add this fix in the next commit. Feel free to close this when you can confirm the fix works. Thanks!

andrewminton commented 13 years ago

Hey Brock,

Tried that but still get error.. something to do with required field checkbox I'm thinking. See my screen shot. http://dl.dropbox.com/u/670078/Screen%20shot%202011-09-30%20at%2009.42.50.png

I have the numeric field with a required checkbox. I'm using latest branch.

brockpetrie commented 13 years ago

It looks like you aren't using the latest dev version.

Version 2.0dev6 fixes the following issue... Fixed validation pattern presets (backslashes weren't being escaped)

You can read me and Nils' discussion about this here; I'm pretty sure this is what's causing your problem.

That version also adds checkbox and radio button subfield types, so you'll be able to use those rather than doing the text input workaround you're using.

andrewminton commented 13 years ago

Noted. Will update. 2.0dev5 in local install. Doh! (Slaphead)

brockpetrie commented 13 years ago

Haha no problem

andrewminton commented 13 years ago

Will pull your branch locally and test while at the Symposium day2 tomorrow. A lot of singing praises for the work youce done here by the way. double kudos

brockpetrie commented 13 years ago

Wow... Thanks a lot, man— I really appreciate that! So great to hear; very, very, inspiring! To be honest, I was a bit worried that nobody would use this thing...

I wish I was there!!