summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2018-07-24 15:06:18 +0200
committerJules Laplace <julescarbon@gmail.com>2018-07-24 15:06:18 +0200
commita0b5692d077544ea2f44b41ed72f0b3c26b3dcf6 (patch)
treed461abcd7a8161fbdd301a639c6ec4f0cc9f04be
parent656fe312be45b2838f9c5397abaa244472c3d0ea (diff)
zipcode check, other error field checkz
-rwxr-xr-xStoneIsland/www/css/account.css15
-rwxr-xr-xStoneIsland/www/js/lib/cart/CartShipping.js17
-rwxr-xr-xStoneIsland/www/js/lib/nav/AddressView.js28
-rwxr-xr-xStoneIsland/www/js/lib/view/Serializable.js16
4 files changed, 64 insertions, 12 deletions
diff --git a/StoneIsland/www/css/account.css b/StoneIsland/www/css/account.css
index b3270a32..26883071 100755
--- a/StoneIsland/www/css/account.css
+++ b/StoneIsland/www/css/account.css
@@ -155,7 +155,6 @@ input[type=text], input[type=password], input[type=number], input[type=email] {
display: block;
margin-top: 4px;
width: calc(100vw - 10px);
- border: 1px solid #a9a9a9;
overflow: auto;
}
@@ -165,7 +164,8 @@ input[type=text], input[type=password], input[type=number], input[type=email] {
border:none;
box-sizing: border-box;
float: left;
- width: 50%;
+ border: 1px solid #a9a9a9;
+ width: 50%;
}
.half-input > input:first-child {
@@ -475,11 +475,15 @@ input.switch:checked + label:after {
.half-input .select-wrapper {
width: 50%;
border: 0;
- margin-top: -1px;
+ margin-top: 0px;
float: left;
+ box-sizing: border-box;
+ border: 1px solid #a9a9a9;
+ border-left: 0px;
}
+
.half-input .select-wrapper span {
- top: 9px;
+ top: 8px;
color: #aaa;
}
.select-wrapper [type=date] {
@@ -516,8 +520,11 @@ input.switch:checked + label:after {
.country-wrapper-static {
text-align: center;
color: #a9a9a9;
+ border: 1px solid;
padding-top: 9px;
font-size: 14px;
+ height: 35px;
+ box-sizing: border-box;
}
.container-row input:first-child {
diff --git a/StoneIsland/www/js/lib/cart/CartShipping.js b/StoneIsland/www/js/lib/cart/CartShipping.js
index 536b5161..ef8f94b7 100755
--- a/StoneIsland/www/js/lib/cart/CartShipping.js
+++ b/StoneIsland/www/js/lib/cart/CartShipping.js
@@ -129,7 +129,22 @@ var CartShipping = FormView.extend({
success: function(){
app.router.go('cart/payment')
},
-
+
+ error: function(res){
+ console.log('error', res.responseJSON)
+ var data = res.responseJSON || { 'Error': { 'Description': 'Unknown' } }
+ const errors = []
+ switch(data['Error']['Description']) {
+ case 'InvalidFormatParameterException:AddressPostalCode':
+ errors.push(['ZipCode', 'Please enter a valid US/Canada Zip Code.'])
+ break
+ default:
+ errors.push(['', 'An unknown error occured.'])
+ break
+ }
+ this.show_errors(errors)
+ },
+
cancel: function(){
app.router.go('cart/summary')
},
diff --git a/StoneIsland/www/js/lib/nav/AddressView.js b/StoneIsland/www/js/lib/nav/AddressView.js
index 1c9540bc..9e0c49b6 100755
--- a/StoneIsland/www/js/lib/nav/AddressView.js
+++ b/StoneIsland/www/js/lib/nav/AddressView.js
@@ -38,9 +38,31 @@ var AddressView = SerializableView.extend({
validate_fields: function(data, errors){
if (this.disabled) { return }
- if (this.checkPhone && ! data.Phone) { errors.push([ "Phone", "Please enter your phone number." ]) }
- if (this.checkPhone && data.Phone && data.Phone.replace(/[^0-9]/g, "").length < 10) { errors.push([ "Phone", "Phone numbers must be at least 10 digits." ]) }
- if (! data.Province || data.Province == "NONE") { errors.push([ "Province", "Please choose your state." ]) }
+ if (this.checkPhone) {
+ var phone_number = data.Phone ? data.Phone.replace(/[^0-9]/g, "") : ""
+ var phone_length = phone_number.length
+ if (phone_length === 0 || ! data.Phone) {
+ errors.push([ "Phone", "Please enter your phone number." ])
+ }
+ else if (phone_length < 10) {
+ errors.push([ "Phone", "Please enter a valid 10 digit US/Canada phone number." ])
+ }
+ else if (phone_length > 10) {
+ errors.push([ "Phone", "International phone numbers are not accepted." ])
+ }
+ else if (data.Phone[0] === '+') {
+ errors.push([ "Phone", "Please enter a valid 10 digit US/Canada phone number. International phone numbers are not accepted." ])
+ }
+ else if (phone_number[0] === '1') {
+ errors.push([ "Phone", "Please enter a valid 10 digit US/Canada phone number. International phone numbers are not accepted." ])
+ }
+ }
+ if (! data.Province || data.Province == "NONE") {
+ errors.push([ "Province", "Please choose your state." ])
+ }
+ if (data.ZipCode && data.ZipCode.length < 5) {
+ errors.push([ "ZipCode", "Please enter a valid zip code." ])
+ }
data.Address = data.Address1 + "\n" + data.Address2
data.UserId = auth.user_id
delete data.Address1
diff --git a/StoneIsland/www/js/lib/view/Serializable.js b/StoneIsland/www/js/lib/view/Serializable.js
index f1c61072..4155f102 100755
--- a/StoneIsland/www/js/lib/view/Serializable.js
+++ b/StoneIsland/www/js/lib/view/Serializable.js
@@ -70,8 +70,9 @@ var SerializableView = View.extend({
update_select: function(e){
var $target = $(e.currentTarget), value = $target.val()
var label = $target.find("option").filter(function(){ return this.value === value }).html()
- $target.parent().addClass("picked")
- $target.parent().find("span").html(label)
+ var $parent = $target.parent()
+ $parent.addClass("picked").removeClass("error_hilite")
+ $parent.find("span").html(label)
},
update_date: function(e){
@@ -103,10 +104,17 @@ var SerializableView = View.extend({
console.log("showing errors")
console.log(errors)
var msgs = []
+ this.$('.error_hilite').removeClass('error_hilite')
errors.forEach(function(e, i){
- if (i > 0) { return }
+ // if (i > 0) { return }
if (e[0]) {
- this.$("[name=" + e[0] + "]").addClass('error_hilite')
+ var $el = this.$("[name=" + e[0] + "]")
+ var el = $el[0]
+ if (el && el.nodeName === 'SELECT') {
+ $el.parent().addClass('error_hilite')
+ } else {
+ $el.addClass('error_hilite')
+ }
}
msgs.push(e[1])
}.bind(this))