plainblack.com
Username Password
search
Bookmark and Share
getValue in WebGUI::Form::Integer doesn't return defaultValue  (#11893)
Issue

The getValue method should return $self->get("defalutValue") instead of the hardcoded value 0.  Having it return 0 makes it impossible to distinguish between an actual 0 (valid integer) and a null value for inserting the record into the database.

Comments
perlDreamer
0
10/2/2010 1:53 pm
Debug notes:
I checked the other form plugins, like Phone, Float, Url and Email, and they all handle the case of illegal input differently:

Integer and Float return 0 and 0.0, respectively
Phone returns undef
Email returns undef,
Url can return ''

There's no consistent return value for the case of receiving bad input.

Each form plugin calls getValue, which eventually calls getValue from Form::Control, which calls getValueFromPost, which calls getDefaultValue if $self->session->form->param($self->name) returns undef.

If we return defaultValue when the input form the form is bad, we could return anything, rather than something that you'd expect from a form, like 0, 0.0, or whatever.

In short, it's a mess.
fdillon
0
10/2/2010 2:57 pm
Yep.  I wound up having to create a custom form field which inherits from integer, but there is another problem.  The definition walks through the hierarchy backward setting the value to whatever the defaultValue is UNLESS it is already defined.  What that means is that since Integer has a defaultValue of 0, I couldn't change the defaultValue to be undef.

Form controls, in short, really are a mess like you said.
fdillon
0
10/2/2010 2:58 pm
Oh, to solve the problem I actually had to call the $self->WebGUI::Form::Text::definition() instead of $self->SUPER::definition()

Really hackish but it does the job.
perlDreamer
0
10/4/2010 2:53 pm
I am told that on 8, form controls will be able to tell you if they were given bad data, so you can highlight the problem to the user.
preaction
0
1/10/2011 4:23 pm
So this can't be fixed without breaking API, correct? This would only be fixed by a field having an error state instead of defaulting to a sane-but-wrong default.
Details
Ticket Status Feedback Requested  
Rating0.0 
Submitted By frank  
Date Submitted2010-10-02 
Assigned To unassigned  
Date Assigned 2019-05-20  
Assigned By  
Priority  
Milestone  
URLuse/bugs/tracker/11893
Keywords
Ticket History
1/10/2011
10:23 PM
Feedback Requested DBell
10/4/2010
7:53 PM
Waiting on External perlDreamer
10/2/2010
4:50 PM
Ticket created frank
© 2019 Plain Black Corporation | All Rights Reserved