html-formhandler icon indicating copy to clipboard operation
html-formhandler copied to clipboard

Field::Money and client form validation in Chrome

Open moltar opened this issue 11 years ago • 7 comments

The Money field sets HTML5 form field type to number. And Chrome has quirky behavior, which seems to be inline with W3C of not allowing decimal numbers by default.

When submitting a form with decimal values, you get the following error message: http://note.io/1kWsrfw

The solution in this article seems to indicate that setting step="any" attribute would fix the problem.

If you accept this solution, I can make a pull request.

moltar avatar Apr 15 '14 10:04 moltar

I had the same problem as a user on a website with Safari on iOS. I assume Gerda is ok with a patch if the value is configurable, if there isn't already a feature that lets you assign arbitrary dom attributes and values.

abraxxa avatar Apr 15 '14 10:04 abraxxa

It is possible to set arbitrary attributes, and to temporary fix it I set it to:

element_attr => { step => ['any'] }

But it feels like most people would want decimals for Money type. But maybe I am feeling it wrong :)

moltar avatar Apr 15 '14 10:04 moltar

IMO we should document it at least that this is such behavior for HTML5.

moltar avatar Apr 15 '14 10:04 moltar

Agreed, but lets wait for Gerda's comment

abraxxa avatar Apr 15 '14 10:04 abraxxa

I think changing the default html5 type is fine. Submit a pull request?

Gerda

On Tue, Apr 15, 2014 at 6:59 AM, Alexander Hartmaier < [email protected]> wrote:

Agreed, but lets wait for Gerda's comment

— Reply to this email directly or view it on GitHubhttps://github.com/gshank/html-formhandler/issues/68#issuecomment-40469155 .

gshank avatar Apr 15 '14 11:04 gshank

Would something like this suffice?

sub BUILD {
   my $self = shift;
   # make sure user hasn't set step already
   if (!$self->get_element_attr('step')) {
       $self->set_element_attr('step', 'any');
   }
}

I am just not sure where is the best place to populate element_attr. If I set it as a attribute, and then user passes some other unrelated attributes then step attribute would be overwritten.

moltar avatar Apr 25 '14 15:04 moltar

Better late than never, sounds good to me! Please don't forget to add docs and a note in the changelog.

abraxxa avatar Apr 03 '20 11:04 abraxxa