Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use HTML5 Validations for Frontend Checkout #1548 #1799

Closed
wants to merge 4 commits into from
Closed

Use HTML5 Validations for Frontend Checkout #1548 #1799

wants to merge 4 commits into from

Conversation

gitmihalis
Copy link

Hey there. This is my first contribution to open source!

I removed the jQuery.validate plugin and added the HTML5 required attributes to the relevant input fields in checkout, as well as a couple of patterns to match basic phone number and email addresses. I don't think there are any new test to write seeing as none of the functionality has changed.

Looking forward to your feedback.

@@ -3,12 +3,12 @@

<p class="field">
<%= label_tag "name_on_card_#{payment_method.id}", Spree.t(:name_on_card) %><span class="required">*</span><br />
<%= text_field_tag "#{param_prefix}[name]", "#{@order.billing_firstname} #{@order.billing_lastname}", { id: "name_on_card_#{payment_method.id}", autocomplete: "cc-name" } %>
<%= text_field_tag "#{param_prefix}[name]", "#{@order.billing_firstname} #{@order.billing_lastname}", { id: "name_on_card_#{payment_method.id}", utocomplete: "cc-name", required: true } %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

@mtomov
Copy link
Contributor

mtomov commented Mar 27, 2017

I am all in favour of this change 👍

  • Foundation for example has a much lighter (read 100 times smaller) validation JS, which looks better and all, so I am having to always remove this jquery validation. It's just too much for 2 forms on the frontend.

Copy link
Contributor

@mtomov mtomov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that all major browsers support HTML5 validations, and that users can easily use add their own validations, I believe it's a good thing to remove jquery validate.

@@ -65,30 +67,31 @@
class: !have_states ? 'required' : '',
style: have_states ? 'display: none;' : '',
disabled: have_states,
autocomplete: address_type + ' address-level1'
autocomplete: address_type + ' address-level1',
required: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The required here should maybe follow the same logic as the required class. !have_states ? 'required' : ''.

Do we maybe need to remove the required class from those inputs as well? And use maybe the required attribute as a selector in the css if there's need.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the !have_states? 'required' logic makes sense for anything else besides styles here. It's simple enough to remove the required: true attribute for a fringe case where address-level1 would not be required, but the form is for Debit/Credit or Shipping which do require an address.

</p>

<p class="field" id=<%="#{address_id}phone" %>>
<%= form.label :phone, Spree.t(:phone) %><% if address.require_phone? %><span class="required">*</span><% end %><br />
<%= form.phone_field :phone, class: "#{'required' if address.require_phone?}", autocomplete: address_type + ' home tel' %>
<%= form.phone_field :phone, class: "#{'required' if address.require_phone?}", autocomplete: address_type + ' home tel', required: true, pattern: '^([+]?\d{1,2}[-\s]?|)\d{3}[-\s]?\d{3}[-\s]?\d{4}$' %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that the RegEx is too complicated to sit in the views, and we'd need tests for it, as at the moment I have no clue what its expected functionality would be.

In addition, any kind of validation in this field would have to consider any sort of telephone number that exists around the world, which I believe is a difficult job. Just recently I was to add an auto-format in this field for the US phone style, which would wrap the first 3 digits I believe it was in parentheses (123) ...

@@ -12,7 +12,7 @@
<% if @order.state == 'address' || !@order.email? %>
<p class="field" style='clear: both'>
<%= form.label :email %><br />
<%= form.text_field :email %>
<%= form.text_field :email, required: true, pattern: "^[a-zA-Z0-9\.]+@[a-zA-Z0-9]+(\-)?[a-zA-Z0-9]+(\.)?[a-zA-Z0-9]{2,6}?\.[a-zA-Z]{2,6}$", title: "username@example.com" %>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as for the phone field is valid here - the logic is too complicated for the view, and it needs to be tested, so to understand what the expected validations are.

But before you go there, consider that there's already sort of an established RegEx in Solidus. See issue #1794 for more info.s

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I could take it out.

@kennyadsl
Copy link
Member

This can be closed since we merged this via #2264, thanks @gitmihalis !

@kennyadsl kennyadsl closed this Nov 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants