html-formhandler
html-formhandler copied to clipboard
Field::Money and client form validation in Chrome
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.
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.
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 :)
IMO we should document it at least that this is such behavior for HTML5.
Agreed, but lets wait for Gerda's comment
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 .
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.
Better late than never, sounds good to me! Please don't forget to add docs and a note in the changelog.