Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
ccdf1fce
Commit
ccdf1fce
authored
Apr 10, 2023
by
dhn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
结算页收货地址和发票地址样式功能修改
parent
081c335a
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
1725 additions
and
45 deletions
+1725
-45
app/code/Magento/Checkout/view/frontend/templates/cart/shipping.phtml
+13
-25
app/code/Magento/Checkout/view/frontend/web/js/model/quote.js
+2
-0
app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js
+12
-3
app/code/Magento/Checkout/view/frontend/web/js/view/part.js
+68
-4
app/code/Magento/Checkout/view/frontend/web/template/billing-address/details.html
+1
-1
app/code/Magento/Theme/view/base/requirejs-config.js
+1
-0
app/code/Magento/Ui/view/base/web/js/form/components/group.js
+15
-2
app/code/Magento/Ui/view/base/web/js/form/element/abstract.js
+10
-2
app/code/Magento/Ui/view/base/web/js/form/element/select.js
+6
-2
app/code/Magento/Ui/view/base/web/js/form/form.js
+7
-0
app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js
+1
-0
app/code/Magento/Ui/view/frontend/web/templates/form/element/select.html
+30
-0
app/code/Magento/Ui/view/frontend/web/templates/form/field.html
+38
-1
app/code/Magento/Ui/view/frontend/web/templates/group/group.html
+27
-0
app/design/frontend/Joshine/breeze/Magento_Checkout/templates/onepage.phtml
+197
-0
app/design/frontend/Joshine/breeze/Magento_Checkout/web/template/form/element/email.html
+4
-5
lib/web/jquery/jquery.validates.js
+1292
-0
lib/web/mage/validation.js
+1
-0
No files found.
app/code/Magento/Checkout/view/frontend/templates/cart/shipping.phtml
View file @
ccdf1fce
...
...
@@ -11,32 +11,20 @@
$selectedCountryId
=
$block
->
getCountryId
();
$flatraPrice
=
$block
->
getFlatratePrice
();
?>
<div
id=
"block-shipping"
class=
"block shipping"
data-mage-init=
'{"collapsible":{"openedState": "active", "saveState": true}}'
>
<div
class=
"title"
data-role=
"title"
>
<strong
id=
"block-shipping-heading"
role=
"heading"
aria-level=
"2"
>
<?=
$block
->
getQuote
()
->
isVirtual
()
?
$block
->
escapeHtml
(
__
(
'Estimate Tax'
))
:
$block
->
escapeHtml
(
__
(
'Estimate Shipping and Tax'
))
?>
</strong>
<div
id=
"block-shipping"
class=
"block shipping"
>
<div
id=
"block-summary"
style=
"display: none;"
>
<form
method=
"post"
id=
"shipping-zip-form"
>
<fieldset
class=
"fieldset estimate"
>
<div
class=
"field"
name=
"shippingAddress.country_id"
>
<label
class=
"label"
for=
"shipping_country_id"
>
<span>
<?=
__
(
'Country'
)
?>
</span>
</label>
<div
class=
"control"
>
<?=
$block
->
getCountryHtmlSelect
(
null
,
'country_id'
,
'shipping_country_id'
)
?>
</div>
<div
id=
"block-summary"
data-bind=
"scope:'block-summary'"
class=
"content"
data-role=
"content"
aria-labelledby=
"block-shipping-heading"
>
<!-- ko template: getTemplate() --><!-- /ko -->
<script
type=
"text/x-magento-init"
>
{
"#block-summary"
:
{
"Magento_Ui/js/core/app"
:
<?=
/* @noEscape */
$block
->
getJsLayout
()
?>
}
}
</script>
</div>
</fieldset>
</form>
<?php
$serializedCheckoutConfig
=
/* @noEscape */
$block
->
getSerializedCheckoutConfig
();
$scriptString
=
<<<script
...
...
app/code/Magento/Checkout/view/frontend/web/js/model/quote.js
View file @
ccdf1fce
...
...
@@ -33,6 +33,7 @@ define([
paymentMethod
=
ko
.
observable
(
null
),
paymentMethodlist
=
ko
.
observable
(
null
),
responseBillStatus
=
ko
.
observable
(
null
),
billAddressMent
=
ko
.
observable
(
null
),
quoteData
=
window
.
checkoutConfig
.
quoteData
,
basePriceFormat
=
window
.
checkoutConfig
.
basePriceFormat
,
priceFormat
=
window
.
checkoutConfig
.
priceFormat
,
...
...
@@ -47,6 +48,7 @@ define([
shippingMethod
:
shippingMethod
,
shippingSaveMethod
:
shippingSaveMethod
,
responseBillStatus
:
responseBillStatus
,
billAddressMent
:
billAddressMent
,
billingAddress
:
billingAddress
,
paymentMethod
:
paymentMethod
,
paymentMethodlist
:
paymentMethodlist
,
...
...
app/code/Magento/Checkout/view/frontend/web/js/view/billing-address.js
View file @
ccdf1fce
...
...
@@ -43,6 +43,7 @@ define([
var
lastSelectedBillingAddress
=
null
,
setCurrentBillingAddress
=
null
,
getCurrentBillingAddress
=
null
,
addressUpadated
=
false
,
addressEdited
=
false
,
countryData
=
customerData
.
get
(
'directory-data'
),
...
...
@@ -81,7 +82,7 @@ define([
this
.
_super
()
.
observe
({
selectedAddress
:
null
,
isAddressDetailsVisible
:
quote
.
billingAddress
()
!
=
null
,
isAddressDetailsVisible
:
getCurrentBillingAddress
=
=
null
,
isAddressFormVisible
:
!
customer
.
isLoggedIn
()
||
!
addressOptions
.
length
,
isAddressSameAsShipping
:
true
,
saveInAddressBook
:
1
...
...
@@ -94,8 +95,6 @@ define([
this
.
saveInAddressBook
(
1
);
}
setCurrentBillingAddress
=
quote
.
billingAddress
();
this
.
isAddressDetailsVisible
(
true
);
},
this
);
return
this
;
...
...
@@ -113,8 +112,17 @@ define([
return
address
.
getAddressInline
();
},
currentBillingAddress
:
function
(){
if
(
getCurrentBillingAddress
)
{
return
getCurrentBillingAddress
;
}
return
setCurrentBillingAddress
;
},
billAddressMent
:
function
(){
return
quote
.
billAddressMent
();
},
/**
* @return {Boolean}
*/
...
...
@@ -164,6 +172,7 @@ define([
// New address must be selected as a billing address
selectBillingAddress
(
newBillingAddress
);
setCurrentBillingAddress
=
newBillingAddress
;
getCurrentBillingAddress
=
newBillingAddress
;
checkoutData
.
setSelectedBillingAddress
(
newBillingAddress
.
getKey
());
checkoutData
.
setNewCustomerBillingAddress
(
addressData
);
}
...
...
app/code/Magento/Checkout/view/frontend/web/js/view/part.js
View file @
ccdf1fce
...
...
@@ -7,6 +7,7 @@ define([
],
function
(
$
,
Component
,
registry
,
checkoutDataResolver
,
quote
)
{
'use strict'
;
var
input_city
=
$
(
'#co-shipping-form input[name="city"]'
);
if
(
input_city
.
is
(
':visible'
)
&&
!
input_city
.
closest
(
'.field'
).
hasClass
(
'_required'
))
{
input_city
.
attr
(
'required'
,
true
);
input_city
.
attr
(
'_required'
,
true
);
...
...
@@ -21,7 +22,8 @@ define([
$
(
document
).
on
(
'click'
,
'#next-shipping>span'
,
function
()
{
var
loginForm
=
$
(
'.form.form-login'
);
var
addressForm
=
$
(
'#checkout-step-shipping>#co-shipping-form'
);
if
(
loginForm
.
length
>
0
&&
!
loginForm
.
validate
().
form
())
{
if
(
loginForm
.
length
>
0
&&
!
loginForm
.
validates
().
form
())
{
return
false
;
}
if
(
addressForm
.
length
>
0
)
{
...
...
@@ -38,12 +40,27 @@ define([
if
(
region_select
.
is
(
':visible'
)
&&
region_select
.
closest
(
'.field'
).
hasClass
(
'_required'
))
{
region_select
.
attr
(
'required'
,
true
);
}
if
(
!
addressForm
.
validate
().
form
())
{
var
selectInput
=
$
(
'#shipping-new-address-form .select-input'
);
if
(
selectInput
.
length
>
0
){
for
(
var
i
=
0
;
i
<
selectInput
.
length
;
i
++
){
var
selectName
=
$
(
selectInput
[
i
]).
next
(
'select'
).
attr
(
'name'
);
$
(
selectInput
[
i
]).
attr
(
'name'
,
selectName
)
}
}
if
(
!
addressForm
.
validates
().
form
())
{
if
(
selectInput
.
length
>
0
){
for
(
var
i
=
0
;
i
<
selectInput
.
length
;
i
++
){
$
(
selectInput
[
i
]).
removeAttr
(
'name'
)
}
}
return
false
;
}
if
(
selectInput
.
length
>
0
){
for
(
var
i
=
0
;
i
<
selectInput
.
length
;
i
++
){
$
(
selectInput
[
i
]).
removeAttr
(
'name'
)
}
}
var
paymentMethodObj
=
$
(
'.checkout-index-index .payment-method'
);
if
(
paymentMethodObj
.
length
<
1
)
{
...
...
@@ -65,6 +82,50 @@ define([
}
if
(
!
registry
.
get
(
'checkout.steps.shipping-step.shippingAddress.after-shipping-method-form.billing-address-form'
).
isAddressSameAsShipping
())
{
var
billadressForm
=
$
(
'.checkout-billing-address form'
);
if
(
billadressForm
.
length
>
0
)
{
if
(
!
$
(
'.checkout-billing-address input[name="region"]'
).
closest
(
'.field'
).
hasClass
(
'_required'
))
{
$
(
'.checkout-billing-address input[name="region"]'
).
removeAttr
(
'required'
);
}
if
(
!
$
(
'.checkout-billing-address input[name="street[1]"]'
).
closest
(
'.field'
).
hasClass
(
'_required'
))
{
$
(
'.checkout-billing-address input[name="street[1]"]'
).
removeAttr
(
'required'
);
}
if
(
!
$
(
'.checkout-billing-address input[name="company"]'
).
closest
(
'.field'
).
hasClass
(
'_required'
))
{
$
(
'.checkout-billing-address input[name="company"]'
).
removeAttr
(
'required'
);
}
var
region_select
=
$
(
'.checkout-billing-address select[name="region_id"]'
);
if
(
region_select
.
is
(
':visible'
)
&&
region_select
.
closest
(
'.field'
).
hasClass
(
'_required'
))
{
region_select
.
attr
(
'required'
,
true
);
}
var
selectInput
=
$
(
'.checkout-billing-address .select-input'
);
if
(
selectInput
.
length
>
0
){
for
(
var
i
=
0
;
i
<
selectInput
.
length
;
i
++
){
var
selectName
=
$
(
selectInput
[
i
]).
next
(
'select'
).
attr
(
'name'
);
$
(
selectInput
[
i
]).
attr
(
'name'
,
selectName
)
}
}
if
(
!
billadressForm
.
validates
().
form
())
{
if
(
selectInput
.
length
>
0
){
for
(
var
i
=
0
;
i
<
selectInput
.
length
;
i
++
){
$
(
selectInput
[
i
]).
removeAttr
(
'name'
)
}
}
return
false
;
}
if
(
selectInput
.
length
>
0
){
for
(
var
i
=
0
;
i
<
selectInput
.
length
;
i
++
){
$
(
selectInput
[
i
]).
removeAttr
(
'name'
)
}
}
}
else
{
return
false
;
}
$
(
'#submitBill'
).
trigger
(
'click'
);
if
(
quote
.
responseBillStatus
()
==
400
)
{
...
...
@@ -87,6 +148,7 @@ define([
$
(
'html,body'
).
animate
({
scrollTop
:
scrollTop
},
'fast'
);
}
checkoutDataResolver
.
resolveEstimationAddress
();
quote
.
billAddressMent
(
true
);
});
$
(
document
).
on
(
'click'
,
'#shipping-text .address-edit'
,
function
()
{
...
...
@@ -129,7 +191,9 @@ define([
{
$
(
'#action-edit-address'
).
trigger
(
'click'
);
}
quote
.
billAddressMent
(
false
);
});
}
});
}
...
...
app/code/Magento/Checkout/view/frontend/web/template/billing-address/details.html
View file @
ccdf1fce
...
...
@@ -4,7 +4,7 @@
* See COPYING.txt for license details.
*/
-->
<div
if=
"isAddressDetailsVisible() && currentBillingAddress()"
class=
"billing-address-details"
>
<div
if=
"isAddressDetailsVisible() && currentBillingAddress()
&& billAddressMent()
"
class=
"billing-address-details"
>
<div
class=
"billing-box"
>
<div
class=
"billing-address-box"
>
<text
args=
"currentBillingAddress().prefix"
></text>
<text
args=
"currentBillingAddress().firstname"
></text>
...
...
app/code/Magento/Theme/view/base/requirejs-config.js
View file @
ccdf1fce
...
...
@@ -30,6 +30,7 @@ var config = {
},
paths
:
{
'jquery/validate'
:
'jquery/jquery.validate'
,
'jquery/validates'
:
'jquery/jquery.validates'
,
'jquery/hover-intent'
:
'jquery/jquery.hoverIntent'
,
'jquery/file-uploader'
:
'jquery/fileUploader/jquery.fileuploader'
,
'prototype'
:
'legacy-build.min'
,
...
...
app/code/Magento/Ui/view/base/web/js/form/components/group.js
View file @
ccdf1fce
...
...
@@ -8,8 +8,9 @@
*/
define
([
'underscore'
,
'uiCollection'
],
function
(
_
,
Collection
)
{
'uiCollection'
,
'jquery'
],
function
(
_
,
Collection
,
$
)
{
'use strict'
;
return
Collection
.
extend
({
...
...
@@ -104,6 +105,18 @@ define([
*/
getPreview
:
function
()
{
return
this
.
elems
.
map
(
'getPreview'
);
},
getStreetState
:
function
()
{
if
(
this
.
elems
()[
0
].
value
.
_latestValue
==
''
&&
this
.
elems
()[
0
].
initialValue
==
''
){
return
false
;
}
return
true
;
},
/**
* Updates data from server.
*/
isCheckoutIndex
:
function
()
{
return
$
(
'body'
).
hasClass
(
'checkout-index-index'
);
}
});
});
app/code/Magento/Ui/view/base/web/js/form/element/abstract.js
View file @
ccdf1fce
...
...
@@ -11,8 +11,9 @@ define([
'mageUtils'
,
'uiLayout'
,
'uiElement'
,
'Magento_Ui/js/lib/validation/validator'
],
function
(
_
,
utils
,
layout
,
Element
,
validator
)
{
'Magento_Ui/js/lib/validation/validator'
,
'jquery'
],
function
(
_
,
utils
,
layout
,
Element
,
validator
,
$
)
{
'use strict'
;
return
Element
.
extend
({
...
...
@@ -482,6 +483,13 @@ define([
}
return
id
;
},
/**
* Updates data from server.
*/
isCheckoutIndex
:
function
()
{
return
$
(
'body'
).
hasClass
(
'checkout-index-index'
);
}
});
});
app/code/Magento/Ui/view/base/web/js/form/element/select.js
View file @
ccdf1fce
...
...
@@ -11,8 +11,9 @@ define([
'mageUtils'
,
'uiRegistry'
,
'./abstract'
,
'uiLayout'
],
function
(
_
,
utils
,
registry
,
Abstract
,
layout
)
{
'uiLayout'
,
'jquery'
],
function
(
_
,
utils
,
registry
,
Abstract
,
layout
,
$
)
{
'use strict'
;
var
inputNode
=
{
...
...
@@ -310,6 +311,9 @@ define([
}
return
this
.
_super
();
},
showNewSelect
:
function
(){
return
$
(
'body'
).
hasClass
(
'checkout-index-index'
);
}
});
});
app/code/Magento/Ui/view/base/web/js/form/form.js
View file @
ccdf1fce
...
...
@@ -356,6 +356,13 @@ define([
makeRequest
(
this
.
params
,
this
.
data
,
this
.
reloadUrl
).
then
(
function
(
data
)
{
app
(
data
,
true
);
});
},
/**
* Updates data from server.
*/
isCheckoutIndex
:
function
()
{
return
$
(
'body'
).
hasClass
(
'checkout-index-index'
);
}
});
});
app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js
View file @
ccdf1fce
...
...
@@ -13,6 +13,7 @@ define([
'moment'
,
'tinycolor'
,
'jquery/validate'
,
'jquery/validates'
,
'mage/translate'
],
function
(
$
,
_
,
utils
,
moment
,
tinycolor
)
{
'use strict'
;
...
...
app/code/Magento/Ui/view/frontend/web/templates/form/element/select.html
View file @
ccdf1fce
...
...
@@ -4,6 +4,7 @@
* See COPYING.txt for license details.
*/
-->
<!-- ko ifnot: isCheckoutIndex() -->
<select
class=
"select"
data-bind=
"
attr: {
name: inputName,
...
...
@@ -26,3 +27,31 @@
}
}"
></select>
<!-- /ko -->
<!-- ko if: isCheckoutIndex() -->
<input
class=
"input-text select-input"
type=
"text"
data-bind=
"value: getPreview(),attr: {
'aria-required': required
}"
required
readonly=
"readonly"
/>
<select
class=
"select check-select"
data-bind=
"
attr: {
name: inputName,
id: uid,
disabled: disabled,
'aria-describedby': getDescriptionId(),
'aria-required': required,
'aria-invalid': error() ? true : 'false',
placeholder: placeholder
},
hasFocus: focused,
optgroup: options,
value: value,
optionsCaption: caption,
optionsValue: 'value',
optionsText: 'label',
optionsAfterRender: function(option, item) {
if (item && item.disabled) {
ko.applyBindingsToNode(option, {attr: {disabled: true}}, item);
}
}"
></select>
<!-- /ko -->
\ No newline at end of file
app/code/Magento/Ui/view/frontend/web/templates/form/field.html
View file @
ccdf1fce
...
...
@@ -4,9 +4,12 @@
* See COPYING.txt for license details.
*/
-->
<!-- ko ifnot: isCheckoutIndex() -->
<div
class=
"field"
data-bind=
"visible: visible, attr: {'name': element.dataScope}, css: additionalClasses"
>
<label
class=
"label"
data-bind=
"attr: { for: element.uid }"
>
<!-- ko if: element.label -->
<span
translate=
"element.label"
></span>
<!-- /ko -->
</label>
<label
class=
"label"
data-bind=
"attr: { for: element.uid }"
>
<!-- ko if: element.label -->
<span
translate=
"element.label"
></span>
<!-- /ko -->
</label>
<div
class=
"control"
data-bind=
"css: {'_with-tooltip': element.tooltip}"
>
<!-- ko ifnot: element.hasAddons() -->
...
...
@@ -50,3 +53,36 @@
<!-- /ko -->
</div>
</div>
<!-- /ko -->
<!-- ko if: isCheckoutIndex() -->
<div
class=
"field"
data-bind=
"visible: visible, attr: {'name': element.dataScope}, css: additionalClasses"
>
<label
class=
"label"
data-bind=
"attr: { for: element.uid },css: {'fouse-label': element.value}"
>
<!-- ko if: element.label -->
<span
translate=
"element.label"
></span>
<!-- /ko -->
</label>
<div
class=
"control"
data-bind=
"css: {'_with-tooltip': element.tooltip}"
>
<!-- ko ifnot: element.hasAddons() -->
<!-- ko template: element.elementTmpl --><!-- /ko -->
<!-- /ko -->
<!-- ko if: element.hasAddons() -->
<div
class=
"control-addon"
>
<!-- ko template: element.elementTmpl --><!-- /ko -->
<!-- ko if: element.addbefore -->
<label
class=
"addon-prefix"
data-bind=
"attr: { for: element.uid }"
><span
data-bind=
"text: element.addbefore"
></span></label>
<!-- /ko -->
<!-- ko if: element.addafter -->
<label
class=
"addon-suffix"
data-bind=
"attr: { for: element.uid }"
><span
data-bind=
"text: element.addafter"
></span></label>
<!-- /ko -->
</div>
<!-- /ko -->
<!-- ko if: element.tooltip -->
<!-- ko template: element.tooltipTpl --><!-- /ko -->
<!-- /ko -->
</div>
</div>
<!-- /ko -->
\ No newline at end of file
app/code/Magento/Ui/view/frontend/web/templates/group/group.html
View file @
ccdf1fce
...
...
@@ -4,6 +4,7 @@
* See COPYING.txt for license details.
*/
-->
<!-- ko ifnot: isCheckoutIndex() -->
<fieldset
class=
"field"
data-bind=
"css: additionalClasses"
>
<legend
class=
"label"
>
<span
translate=
"element.label"
></span>
...
...
@@ -34,3 +35,28 @@
<!-- /ko -->
</div>
</fieldset>
<!-- /ko -->
<!-- ko if: isCheckoutIndex() -->
<fieldset
class=
"field"
data-bind=
"css: additionalClasses"
>
<legend
class=
"label"
data-bind=
"css: {'fouse-label': getStreetState()}"
>
<span
translate=
"element.label"
></span>
</legend>
<div
class=
"control"
>
<!-- ko foreach: { data: elems, as: 'element' } -->
<!-- ko if: element.visible() -->
<!-- ko ifnot: (element.input_type == 'checkbox' || element.input_type == 'radio') -->
<!-- ko template: $parent.fieldTemplate --><!-- /ko -->
<!-- /ko -->
<!-- ko if: (element.input_type == 'checkbox' || element.input_type == 'radio') -->
<!-- ko template: element.elementTmpl --><!-- /ko -->
<!-- /ko -->
<!-- /ko -->
<!-- /ko -->
</div>
</fieldset>
<!-- /ko -->
\ No newline at end of file
app/design/frontend/Joshine/breeze/Magento_Checkout/templates/onepage.phtml
View file @
ccdf1fce
...
...
@@ -871,10 +871,98 @@ $full_free_ship = $_helper->currency($full_free, true, false);
.checkout-index-index
.page-header
.header.content
.logo
{
left
:
35%
;
}
.checkout-index-index
.form-shipping-address
{
margin-top
:
2rem
;
}
}
.checkout-index-index
#shipping
.field.street
{
min-height
:
7rem
;
}
.checkout-index-index
#shipping
.field.street
.field.additional
.control
input
[
type
=
"text"
]
{
padding
:
0
;
}
.checkout-index-index
#shipping
.field.street
.control
{
border
:
none
;
}
.checkout-index-index
#shipping
.field.street
.control
.field
.control
{
border
:
1px
solid
#ddd
;
}
.checkout-index-index
#shipping
.field.field-select-billing
.control
{
border
:
none
;
}
.checkout-index-index
.opc
.field-select-billing
.label
{
border-bottom
:
none
;
}
.checkout-index-index
.select-style
{
height
:
3rem
;
z-index
:
2
;
transition
:
all
.3s
ease
;
border
:
1px
solid
#ddd
;
}
.checkout-index-index
.error-border-style
{
border
:
1px
solid
#fa320f
!important
;
}
.checkout-index-index
.select-input
{
cursor
:
pointer
;
}
.fieldset.address
.check-select
{
z-index
:
2
;
display
:
none
;
}
.checkout-index-index
#customer-password
{
height
:
50px
;
outline
:
none
;
text-indent
:
10px
;
padding
:
18px
0
0
;
border
:
none
;
color
:
#515151
;
background
:
0
0
;
}
/************************************* top logo style end******************************************************/
/********************************************address from end****************************************************/
#shipping
.field
{
position
:
relative
;
}
#shipping
.field
.label
{
position
:
absolute
;
z-index
:
1
;
top
:
15px
;
line-height
:
18px
;
transition
:
all
.3s
ease
;
margin-left
:
0.5rem
;
}
#shipping
.field
.control
{
height
:
50px
;
border
:
1px
solid
#ddd
;
}
#shipping
.field.required
.label
::before
,
#shipping
.field._required
.label
::before
{
content
:
'*'
;
color
:
rgba
(
var
(
--danger-color
),
var
(
--danger-alpha
,
1
));
}
#shipping
.field.required
.label
::after
,
#shipping
.field._required
.label
::after
{
content
:
''
;
}
#shipping
.field
._with-tooltip
.field-tooltip
{
/*position: static;*/
vertical-align
:
middle
;
}
#shipping
.field
.control
input
[
type
=
"text"
],
#maincontent
input
[
type
=
"email"
]
{
height
:
50px
;
outline
:
none
;
text-indent
:
10px
;
padding
:
18px
0
0
;
border
:
none
;
color
:
#515151
;
background
:
0
0
;
}
#shipping
.fouse-label
{
top
:
5px
!important
;
}
/********************************************address from end****************************************************/
</style>
<div
id=
"checkout"
data-bind=
"scope:'checkout'"
class=
"checkout-container"
>
...
...
@@ -953,5 +1041,113 @@ script;
});
}
$
(
document
).
on
(
'focus'
,
'#shipping input[type="email"],#shipping input[type="password"],#shipping input[type="text"]'
,
function
()
{
if
(
$
(
this
).
hasClass
(
'select-input'
))
{
return
false
;
}
if
(
!
$
(
this
).
parent
().
prev
(
'label'
).
hasClass
(
'fouse-label'
)){
$
(
this
).
parent
().
prev
(
'label'
).
addClass
(
'fouse-label'
)
}
});
$
(
document
).
on
(
'blur'
,
'#shipping input[type="email"],#shipping input[type="password"],#shipping input[type="text"]'
,
function
()
{
if
(
$
(
this
).
hasClass
(
'select-input'
))
{
return
false
;
}
if
(
$
(
this
).
parent
().
prev
(
'label'
).
hasClass
(
'fouse-label'
)){
if
(
$
(
this
).
val
()
==
''
){
$
(
this
).
parent
().
prev
(
'label'
).
removeClass
(
'fouse-label'
)
}
}
if
(
$
(
this
).
attr
(
'aria-required'
)
==
'true'
)
{
var
thisVal
=
$
(
this
).
val
();
if
(
thisVal
===
''
||
thisVal
==
null
||
thisVal
.
length
===
0
||
/^
\s
+$/
.
test
(
thisVal
))
{
$
(
this
).
addClass
(
'error-border-style'
)
}
else
if
(
$
(
this
).
hasClass
(
'error-border-style'
))
{
$
(
this
).
removeClass
(
'error-border-style'
)
}
}
});
$
(
document
).
on
(
'focus'
,
'#shipping .field.street ._required input[type="text"]'
,
function
()
{
if
(
!
$
(
this
).
parent
().
parent
().
parent
().
prev
(
'.label'
).
hasClass
(
'fouse-label'
)){
$
(
this
).
parent
().
parent
().
parent
().
prev
(
'.label'
).
addClass
(
'fouse-label'
)
}
});
$
(
document
).
on
(
'blur'
,
'#shipping .field.street ._required input[type="text"]'
,
function
()
{
if
(
$
(
this
).
parent
().
parent
().
parent
().
prev
(
'.label'
).
hasClass
(
'fouse-label'
)){
var
thisVal
=
$
(
this
).
val
();
if
(
thisVal
===
''
||
thisVal
==
null
||
thisVal
.
length
===
0
||
/^
\s
+$/
.
test
(
thisVal
))
{
$
(
this
).
addClass
(
'error-border-style'
);
$
(
this
).
parent
().
parent
().
parent
().
prev
(
'.label'
).
removeClass
(
'fouse-label'
)
}
else
if
(
$
(
this
).
hasClass
(
'error-border-style'
))
{
$
(
this
).
removeClass
(
'error-border-style'
)
}
}
});
//select-input
$
(
document
).
on
(
'click'
,
'#shipping .select-input'
,
function
()
{
if
(
$
(
this
).
next
(
'.select'
).
is
(
':visible'
))
{
$
(
this
).
next
(
'.select'
).
hide
();
$
(
this
).
next
(
'.select'
).
removeClass
(
'select-style'
)
if
(
$
(
this
).
val
()
==
''
)
{
if
(
$
(
this
).
parent
().
prev
(
'.label'
).
hasClass
(
'fouse-label'
)){
$
(
this
).
parent
().
prev
(
'.label'
).
removeClass
(
'fouse-label'
);
}
}
}
else
{
$
(
this
).
next
(
'.select'
).
show
();
$
(
this
).
next
(
'.select'
).
addClass
(
'select-style'
);
if
(
$
(
this
).
val
()
==
''
)
{
$
(
this
).
parent
().
prev
(
'.label'
).
addClass
(
'fouse-label'
);
}
}
});
//check-select
$
(
document
).
on
(
'click'
,
'#shipping .check-select'
,
function
()
{
$
(
document
).
on
(
'change'
,
'#shipping .check-select'
,
function
()
{
if
(
$
(
this
).
val
()
!=
''
)
{
if
(
$
(
this
).
val
()
==
'-'
)
{
$
(
this
).
prev
(
'input'
).
addClass
(
'error-border-style'
);
}
else
{
$
(
this
).
hide
();
$
(
this
).
removeClass
(
'select-style'
);
if
(
$
(
this
).
prev
(
'input'
).
hasClass
(
'error-border-style'
)){
$
(
this
).
prev
(
'input'
).
removeClass
(
'error-border-style'
);
}
}
}
else
{
$
(
this
).
prev
(
'input'
).
addClass
(
'error-border-style'
);
}
});
});
});
</script>
\ No newline at end of file
app/design/frontend/Joshine/breeze/Magento_Checkout/web/template/form/element/email.html
View file @
ccdf1fce
...
...
@@ -14,7 +14,10 @@
method=
"post"
>
<fieldset
id=
"customer-email-fieldset"
class=
"fieldset"
data-bind=
"blockLoader: isLoading"
>
<div
class=
"field required"
>
<label
class=
"label"
for=
"customer-email"
><span
data-bind=
"i18n: 'Email Address'"
></span>
<!-- ko template: 'ui/form/element/helper/tooltip' --><!-- /ko -->
</label>
<label
class=
"label"
for=
"customer-email"
data-bind=
"css:{'fouse-label': email}"
>
<span
data-bind=
"i18n: 'Email Address'"
></span>
<!-- ko template: 'ui/form/element/helper/tooltip' --><!-- /ko -->
</label>
<div
class=
"control _with-tooltip"
>
<input
class=
"input-text"
type=
"email"
...
...
@@ -37,10 +40,6 @@
<label
class=
"label"
for=
"customer-password"
><span
data-bind=
"i18n: 'Password'"
></span></label>
<div
class=
"control"
>
<input
class=
"input-text"
data-bind=
"
attr: {
placeholder: $t('Password'),
}"
type=
"password"
name=
"password"
id=
"customer-password"
...
...
lib/web/jquery/jquery.validates.js
0 → 100644
View file @
ccdf1fce
/**
* jQuery Validation Plugin @VERSION
*
* http://bassistance.de/jquery-plugins/jquery-plugin-validation/
* http://docs.jquery.com/Plugins/Validation
*
* Copyright (c) 2012 Jörn Zaefferer
*
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(
function
(
factory
)
{
if
(
typeof
define
===
'function'
&&
define
.
amd
)
{
define
([
"jquery"
,
"jquery/jquery.metadata"
],
factory
);
}
else
{
factory
(
jQuery
);
}
}(
function
(
jQuery
)
{
(
function
(
$
)
{
$
.
extend
(
$
.
fn
,
{
// http://docs.jquery.com/Plugins/Validation/validate
validates
:
function
(
options
)
{
// if nothing is selected, return nothing; can't chain anyway
if
(
!
this
.
length
)
{
if
(
options
&&
options
.
debug
&&
window
.
console
)
{
console
.
warn
(
"nothing selected, can't validate, returning nothing"
);
}
return
;
}
// check if a validator for this form was already created
var
validator
=
$
.
data
(
this
[
0
],
'validator'
);
if
(
validator
)
{
return
validator
;
}
// Add novalidate tag if HTML5.
this
.
attr
(
'novalidate'
,
'novalidate'
);
validator
=
new
$
.
validator
(
options
,
this
[
0
]);
$
.
data
(
this
[
0
],
'validator'
,
validator
);
if
(
validator
.
settings
.
onsubmit
)
{
this
.
validateDelegate
(
":submit"
,
"click"
,
function
(
ev
)
{
if
(
validator
.
settings
.
submitHandler
)
{
validator
.
submitButton
=
ev
.
target
;
}
// allow suppressing validation by adding a cancel class to the submit button
if
(
$
(
ev
.
target
).
hasClass
(
'cancel'
))
{
validator
.
cancelSubmit
=
true
;
}
});
// validate the form on submit
this
.
submit
(
function
(
event
)
{
if
(
validator
.
settings
.
debug
)
{
// prevent form submit to be able to see console output
event
.
preventDefault
();
}
function
handle
()
{
var
hidden
;
if
(
validator
.
settings
.
submitHandler
)
{
if
(
validator
.
submitButton
)
{
// insert a hidden input as a replacement for the missing submit button
hidden
=
$
(
"<input type='hidden'/>"
).
attr
(
"name"
,
validator
.
submitButton
.
name
).
val
(
validator
.
submitButton
.
value
).
appendTo
(
validator
.
currentForm
);
}
validator
.
settings
.
submitHandler
.
call
(
validator
,
validator
.
currentForm
,
event
);
if
(
validator
.
submitButton
)
{
// and clean up afterwards; thanks to no-block-scope, hidden can be referenced
hidden
.
remove
();
}
return
false
;
}
return
true
;
}
// prevent submit for invalid forms or custom submit handlers
if
(
validator
.
cancelSubmit
)
{
validator
.
cancelSubmit
=
false
;
return
handle
();
}
if
(
validator
.
form
())
{
if
(
validator
.
pendingRequest
)
{
validator
.
formSubmitted
=
true
;
return
false
;
}
return
handle
();
}
else
{
validator
.
focusInvalid
();
return
false
;
}
});
}
return
validator
;
},
// http://docs.jquery.com/Plugins/Validation/valid
valid
:
function
()
{
if
(
$
(
this
[
0
]).
is
(
'form'
))
{
return
this
.
validates
().
form
();
}
else
{
var
valid
=
true
;
var
validator
=
$
(
this
[
0
].
form
).
validates
();
this
.
each
(
function
()
{
valid
&=
validator
.
element
(
this
);
});
return
valid
;
}
},
// attributes: space seperated list of attributes to retrieve and remove
removeAttrs
:
function
(
attributes
)
{
var
result
=
{},
$element
=
this
;
$
.
each
(
attributes
.
split
(
/
\s
/
),
function
(
index
,
value
)
{
result
[
value
]
=
$element
.
attr
(
value
);
$element
.
removeAttr
(
value
);
});
return
result
;
},
// http://docs.jquery.com/Plugins/Validation/rules
rules
:
function
(
command
,
argument
)
{
var
element
=
this
[
0
];
if
(
command
)
{
var
settings
=
$
.
data
(
element
.
form
,
'validator'
).
settings
;
var
staticRules
=
settings
.
rules
;
var
existingRules
=
$
.
validator
.
staticRules
(
element
);
switch
(
command
)
{
case
"add"
:
$
.
extend
(
existingRules
,
$
.
validator
.
normalizeRule
(
argument
));
staticRules
[
element
.
name
]
=
existingRules
;
if
(
argument
.
messages
)
{
settings
.
messages
[
element
.
name
]
=
$
.
extend
(
settings
.
messages
[
element
.
name
],
argument
.
messages
);
}
break
;
case
"remove"
:
if
(
!
argument
)
{
delete
staticRules
[
element
.
name
];
return
existingRules
;
}
var
filtered
=
{};
$
.
each
(
argument
.
split
(
/
\s
/
),
function
(
index
,
method
)
{
filtered
[
method
]
=
existingRules
[
method
];
delete
existingRules
[
method
];
});
return
filtered
;
}
}
var
data
=
$
.
validator
.
normalizeRules
(
$
.
extend
(
{},
$
.
validator
.
metadataRules
(
element
),
$
.
validator
.
classRules
(
element
),
$
.
validator
.
attributeRules
(
element
),
$
.
validator
.
staticRules
(
element
)
),
element
);
// make sure required is at front
if
(
data
.
required
)
{
var
param
=
data
.
required
;
delete
data
.
required
;
data
=
$
.
extend
({
required
:
param
},
data
);
}
return
data
;
}
});
// Custom selectors
$
.
extend
(
$
.
expr
[
":"
],
{
// http://docs.jquery.com/Plugins/Validation/blank
blank
:
function
(
a
)
{
return
!
$
.
trim
(
""
+
a
.
value
);
},
// http://docs.jquery.com/Plugins/Validation/filled
filled
:
function
(
a
)
{
return
!!
$
.
trim
(
""
+
a
.
value
);
},
// http://docs.jquery.com/Plugins/Validation/unchecked
unchecked
:
function
(
a
)
{
return
!
a
.
checked
;
}
});
// constructor for validator
$
.
validator
=
function
(
options
,
form
)
{
this
.
settings
=
$
.
extend
(
true
,
{},
$
.
validator
.
defaults
,
options
);
this
.
currentForm
=
form
;
this
.
init
();
};
$
.
validator
.
format
=
function
(
source
,
params
)
{
if
(
arguments
.
length
===
1
)
{
return
function
()
{
var
args
=
$
.
makeArray
(
arguments
);
args
.
unshift
(
source
);
return
$
.
validator
.
format
.
apply
(
this
,
args
);
};
}
if
(
arguments
.
length
>
2
&&
params
.
constructor
!==
Array
)
{
params
=
$
.
makeArray
(
arguments
).
slice
(
1
);
}
if
(
params
.
constructor
!==
Array
)
{
params
=
[
params
];
}
$
.
each
(
params
,
function
(
i
,
n
)
{
source
=
source
.
replace
(
new
RegExp
(
"
\\
{"
+
i
+
"
\\
}"
,
"g"
),
n
);
});
return
source
;
};
$
.
extend
(
$
.
validator
,
{
defaults
:
{
messages
:
{},
groups
:
{},
rules
:
{},
errorClass
:
"error"
,
validClass
:
"valid"
,
errorElement
:
"label"
,
focusInvalid
:
true
,
errorContainer
:
$
([]),
errorLabelContainer
:
$
([]),
onsubmit
:
true
,
ignore
:
":hidden"
,
ignoreTitle
:
false
,
onfocusin
:
function
(
element
,
event
)
{
this
.
lastActive
=
element
;
// hide error label and remove error class on focus if enabled
if
(
this
.
settings
.
focusCleanup
&&
!
this
.
blockFocusCleanup
)
{
if
(
this
.
settings
.
unhighlight
)
{
this
.
settings
.
unhighlight
.
call
(
this
,
element
,
this
.
settings
.
errorClass
,
this
.
settings
.
validClass
);
}
this
.
addWrapper
(
this
.
errorsFor
(
element
)).
hide
();
}
},
onfocusout
:
function
(
element
,
event
)
{
if
(
!
this
.
checkable
(
element
)
&&
(
element
.
name
in
this
.
submitted
||
!
this
.
optional
(
element
)))
{
this
.
element
(
element
);
}
},
onkeyup
:
function
(
element
,
event
)
{
if
(
event
.
which
==
9
&&
this
.
elementValue
(
element
)
===
''
)
{
return
;
}
else
if
(
element
.
name
in
this
.
submitted
||
element
===
this
.
lastActive
)
{
this
.
element
(
element
);
}
},
onclick
:
function
(
element
,
event
)
{
// click on selects, radiobuttons and checkboxes
if
(
element
.
name
in
this
.
submitted
)
{
this
.
element
(
element
);
}
// or option elements, check parent select in that case
else
if
(
element
.
parentNode
.
name
in
this
.
submitted
)
{
this
.
element
(
element
.
parentNode
);
}
},
highlight
:
function
(
element
,
errorClass
,
validClass
)
{
if
(
element
.
type
===
'radio'
)
{
this
.
findByName
(
element
.
name
).
addClass
(
errorClass
).
removeClass
(
validClass
);
}
else
{
$
(
element
).
addClass
(
errorClass
).
removeClass
(
validClass
);
}
},
unhighlight
:
function
(
element
,
errorClass
,
validClass
)
{
if
(
element
.
type
===
'radio'
)
{
this
.
findByName
(
element
.
name
).
removeClass
(
errorClass
).
addClass
(
validClass
);
}
else
{
$
(
element
).
removeClass
(
errorClass
).
addClass
(
validClass
);
}
}
},
// http://docs.jquery.com/Plugins/Validation/Validator/setDefaults
setDefaults
:
function
(
settings
)
{
$
.
extend
(
$
.
validator
.
defaults
,
settings
);
},
messages
:
{
required
:
"This field is required."
,
remote
:
"Please fix this field."
,
email
:
"Please enter a valid email address."
,
url
:
"Please enter a valid URL."
,
date
:
"Please enter a valid date."
,
dateISO
:
"Please enter a valid date (ISO)."
,
number
:
"Please enter a valid number."
,
digits
:
"Please enter only digits."
,
creditcard
:
"Please enter a valid credit card number."
,
equalTo
:
"Please enter the same value again."
,
maxlength
:
$
.
validator
.
format
(
"Please enter no more than {0} characters."
),
minlength
:
$
.
validator
.
format
(
"Please enter at least {0} characters."
),
rangelength
:
$
.
validator
.
format
(
"Please enter a value between {0} and {1} characters long."
),
range
:
$
.
validator
.
format
(
"Please enter a value between {0} and {1}."
),
max
:
$
.
validator
.
format
(
"Please enter a value less than or equal to {0}."
),
min
:
$
.
validator
.
format
(
"Please enter a value greater than or equal to {0}."
)
},
autoCreateRanges
:
false
,
prototype
:
{
init
:
function
()
{
this
.
labelContainer
=
$
(
this
.
settings
.
errorLabelContainer
);
this
.
errorContext
=
this
.
labelContainer
.
length
&&
this
.
labelContainer
||
$
(
this
.
currentForm
);
this
.
containers
=
$
(
this
.
settings
.
errorContainer
).
add
(
this
.
settings
.
errorLabelContainer
);
this
.
submitted
=
{};
this
.
valueCache
=
{};
this
.
pendingRequest
=
0
;
this
.
pending
=
{};
this
.
invalid
=
{};
this
.
reset
();
var
groups
=
(
this
.
groups
=
{});
$
.
each
(
this
.
settings
.
groups
,
function
(
key
,
value
)
{
$
.
each
(
value
.
split
(
/
\s
/
),
function
(
index
,
name
)
{
groups
[
name
]
=
key
;
});
});
var
rules
=
this
.
settings
.
rules
;
$
.
each
(
rules
,
function
(
key
,
value
)
{
rules
[
key
]
=
$
.
validator
.
normalizeRule
(
value
);
});
function
delegate
(
event
)
{
var
validator
=
$
.
data
(
this
[
0
].
form
,
"validator"
),
eventType
=
"on"
+
event
.
type
.
replace
(
/^validate/
,
""
);
if
(
validator
.
settings
[
eventType
])
{
validator
.
settings
[
eventType
].
call
(
validator
,
this
[
0
],
event
);
}
}
$
(
this
.
currentForm
)
.
validateDelegate
(
":text, [type='password'], [type='file'], select, textarea, "
+
"[type='number'], [type='search'], input.search, [type='tel'], [type='url'], "
+
"[type='email'], [type='datetime'], [type='date'], [type='month'], "
+
"[type='week'], [type='time'], [type='datetime-local'], "
+
"[type='range'], [type='color'] "
,
"focusin focusout keyup"
,
delegate
)
.
validateDelegate
(
"[type='radio'], [type='checkbox'], select, option"
,
"click"
,
delegate
);
if
(
this
.
settings
.
invalidHandler
)
{
$
(
this
.
currentForm
).
bind
(
"invalid-form.validate"
,
this
.
settings
.
invalidHandler
);
}
},
// http://docs.jquery.com/Plugins/Validation/Validator/form
form
:
function
()
{
this
.
checkForm
();
$
.
extend
(
this
.
submitted
,
this
.
errorMap
);
this
.
invalid
=
$
.
extend
({},
this
.
errorMap
);
if
(
!
this
.
valid
())
{
$
(
this
.
currentForm
).
triggerHandler
(
"invalid-form"
,
[
this
]);
}
this
.
showErrors
();
return
this
.
valid
();
},
checkForm
:
function
()
{
this
.
prepareForm
();
for
(
var
i
=
0
,
elements
=
(
this
.
currentElements
=
this
.
elements
());
elements
[
i
];
i
++
)
{
this
.
check
(
elements
[
i
]);
}
return
this
.
valid
();
},
// http://docs.jquery.com/Plugins/Validation/Validator/element
element
:
function
(
element
)
{
element
=
this
.
validationTargetFor
(
this
.
clean
(
element
));
this
.
lastElement
=
element
;
this
.
prepareElement
(
element
);
this
.
currentElements
=
$
(
element
);
var
result
=
this
.
check
(
element
)
!==
false
;
if
(
result
)
{
delete
this
.
invalid
[
element
.
name
];
}
else
{
this
.
invalid
[
element
.
name
]
=
true
;
}
if
(
!
this
.
numberOfInvalids
())
{
// Hide error containers on last error
this
.
toHide
=
this
.
toHide
.
add
(
this
.
containers
);
}
this
.
showErrors
();
return
result
;
},
// http://docs.jquery.com/Plugins/Validation/Validator/showErrors
showErrors
:
function
(
errors
)
{
if
(
errors
)
{
// add items to error list and map
$
.
extend
(
this
.
errorMap
,
errors
);
this
.
errorList
=
[];
for
(
var
name
in
errors
)
{
this
.
errorList
.
push
({
message
:
errors
[
name
],
element
:
this
.
findByName
(
name
)[
0
]
});
}
// remove items from success list
this
.
successList
=
$
.
grep
(
this
.
successList
,
function
(
element
)
{
return
!
(
element
.
name
in
errors
);
});
}
if
(
this
.
settings
.
showErrors
)
{
this
.
settings
.
showErrors
.
call
(
this
,
this
.
errorMap
,
this
.
errorList
);
}
else
{
this
.
defaultShowErrors
();
}
},
// http://docs.jquery.com/Plugins/Validation/Validator/resetForm
resetForm
:
function
()
{
if
(
$
.
fn
.
resetForm
)
{
$
(
this
.
currentForm
).
resetForm
();
}
this
.
submitted
=
{};
this
.
lastElement
=
null
;
this
.
prepareForm
();
this
.
hideErrors
();
this
.
elements
().
removeClass
(
this
.
settings
.
errorClass
).
removeData
(
"previousValue"
);
},
numberOfInvalids
:
function
()
{
return
this
.
objectLength
(
this
.
invalid
);
},
objectLength
:
function
(
obj
)
{
var
count
=
0
;
for
(
var
i
in
obj
)
{
count
++
;
}
return
count
;
},
hideErrors
:
function
()
{
this
.
addWrapper
(
this
.
toHide
).
hide
();
},
valid
:
function
()
{
return
this
.
size
()
===
0
;
},
size
:
function
()
{
return
this
.
errorList
.
length
;
},
focusInvalid
:
function
()
{
if
(
this
.
settings
.
focusInvalid
)
{
try
{
$
(
this
.
findLastActive
()
||
this
.
errorList
.
length
&&
this
.
errorList
[
0
].
element
||
[])
.
filter
(
":visible"
)
.
focus
()
// manually trigger focusin event; without it, focusin handler isn't called, findLastActive won't have anything to find
.
trigger
(
"focusin"
);
}
catch
(
e
)
{
// ignore IE throwing errors when focusing hidden elements
}
}
},
findLastActive
:
function
()
{
var
lastActive
=
this
.
lastActive
;
return
lastActive
&&
$
.
grep
(
this
.
errorList
,
function
(
n
)
{
return
n
.
element
.
name
===
lastActive
.
name
;
}).
length
===
1
&&
lastActive
;
},
elements
:
function
()
{
var
validator
=
this
,
rulesCache
=
{};
// select all valid inputs inside the form (no submit or reset buttons)
return
$
(
this
.
currentForm
)
.
find
(
"input, select, textarea"
)
.
not
(
":submit, :reset, :image, [disabled]"
)
.
not
(
this
.
settings
.
ignore
)
.
filter
(
function
()
{
if
(
!
this
.
name
&&
validator
.
settings
.
debug
&&
window
.
console
)
{
console
.
error
(
"%o has no name assigned"
,
this
);
}
// select only the first element for each name, and only those with rules specified
if
(
this
.
name
in
rulesCache
||
!
validator
.
objectLength
(
$
(
this
).
rules
()))
{
return
false
;
}
rulesCache
[
this
.
name
]
=
true
;
return
true
;
});
},
clean
:
function
(
selector
)
{
return
$
(
selector
)[
0
];
},
errors
:
function
()
{
var
errorClass
=
this
.
settings
.
errorClass
.
replace
(
' '
,
'.'
);
return
$
(
this
.
settings
.
errorElement
+
"."
+
errorClass
,
this
.
errorContext
);
},
reset
:
function
()
{
this
.
successList
=
[];
this
.
errorList
=
[];
this
.
errorMap
=
{};
this
.
toShow
=
$
([]);
this
.
toHide
=
$
([]);
this
.
currentElements
=
$
([]);
},
prepareForm
:
function
()
{
this
.
reset
();
this
.
toHide
=
this
.
errors
().
add
(
this
.
containers
);
},
prepareElement
:
function
(
element
)
{
this
.
reset
();
this
.
toHide
=
this
.
errorsFor
(
element
);
},
elementValue
:
function
(
element
)
{
var
type
=
$
(
element
).
attr
(
'type'
),
val
=
$
(
element
).
val
();
if
(
type
===
'radio'
||
type
===
'checkbox'
)
{
return
$
(
'input[name="'
+
$
(
element
).
attr
(
'name'
)
+
'"]:checked'
).
val
();
}
if
(
typeof
val
===
'string'
)
{
return
val
.
replace
(
/
\r
/g
,
""
);
}
return
val
;
},
check
:
function
(
element
)
{
element
=
this
.
validationTargetFor
(
this
.
clean
(
element
));
var
rules
=
$
(
element
).
rules
();
var
dependencyMismatch
=
false
;
var
val
=
this
.
elementValue
(
element
);
var
result
;
for
(
var
method
in
rules
)
{
var
rule
=
{
method
:
method
,
parameters
:
rules
[
method
]
};
try
{
result
=
$
.
validator
.
methods
[
method
].
call
(
this
,
val
,
element
,
rule
.
parameters
);
// if a method indicates that the field is optional and therefore valid,
// don't mark it as valid when there are no other rules
if
(
result
===
"dependency-mismatch"
)
{
dependencyMismatch
=
true
;
continue
;
}
dependencyMismatch
=
false
;
if
(
result
===
"pending"
)
{
this
.
toHide
=
this
.
toHide
.
not
(
this
.
errorsFor
(
element
));
return
;
}
if
(
!
result
)
{
this
.
formatAndAdd
(
element
,
rule
);
return
false
;
}
}
catch
(
e
)
{
if
(
this
.
settings
.
debug
&&
window
.
console
)
{
console
.
log
(
"exception occurred when checking element "
+
element
.
id
+
", check the '"
+
rule
.
method
+
"' method"
,
e
);
}
throw
e
;
}
}
if
(
dependencyMismatch
)
{
return
;
}
if
(
this
.
objectLength
(
rules
))
{
this
.
successList
.
push
(
element
);
}
return
true
;
},
// return the custom message for the given element and validation method
// specified in the element's "messages" metadata
customMetaMessage
:
function
(
element
,
method
)
{
if
(
!
$
.
metadata
)
{
return
;
}
var
meta
=
this
.
settings
.
meta
?
$
(
element
).
metadata
()[
this
.
settings
.
meta
]
:
$
(
element
).
metadata
();
return
meta
&&
meta
.
messages
&&
meta
.
messages
[
method
];
},
// return the custom message for the given element and validation method
// specified in the element's HTML5 data attribute
customDataMessage
:
function
(
element
,
method
)
{
return
$
(
element
).
data
(
'msg-'
+
method
.
toLowerCase
())
||
(
element
.
attributes
&&
$
(
element
).
attr
(
'data-msg-'
+
method
.
toLowerCase
()));
},
// return the custom message for the given element name and validation method
customMessage
:
function
(
name
,
method
)
{
var
m
=
this
.
settings
.
messages
[
name
];
return
m
&&
(
m
.
constructor
===
String
?
m
:
m
[
method
]);
},
// return the first defined argument, allowing empty strings
findDefined
:
function
()
{
for
(
var
i
=
0
;
i
<
arguments
.
length
;
i
++
)
{
if
(
arguments
[
i
]
!==
undefined
)
{
return
arguments
[
i
];
}
}
return
undefined
;
},
defaultMessage
:
function
(
element
,
method
)
{
var
noMessage
=
$
.
mage
.
__
(
"Warning: No message defined for %s"
);
return
this
.
findDefined
(
this
.
customMessage
(
element
.
name
,
method
),
this
.
customDataMessage
(
element
,
method
),
this
.
customMetaMessage
(
element
,
method
),
// title is never undefined, so handle empty string as undefined
!
this
.
settings
.
ignoreTitle
&&
element
.
title
||
undefined
,
$
.
validator
.
messages
[
method
],
"<strong>"
+
noMessage
.
replace
(
'%s'
,
element
.
name
)
+
"</strong>"
);
},
formatAndAdd
:
function
(
element
,
rule
)
{
var
message
=
this
.
defaultMessage
(
element
,
rule
.
method
),
theregex
=
/
\$?\{(\d
+
)\}
/g
;
if
(
typeof
message
===
"function"
)
{
message
=
message
.
call
(
this
,
rule
.
parameters
,
element
);
}
else
if
(
theregex
.
test
(
message
))
{
message
=
$
.
validator
.
format
(
message
.
replace
(
theregex
,
'{$1}'
),
rule
.
parameters
);
}
this
.
errorList
.
push
({
message
:
message
,
element
:
element
});
this
.
errorMap
[
element
.
name
]
=
message
;
this
.
submitted
[
element
.
name
]
=
message
;
},
addWrapper
:
function
(
toToggle
)
{
if
(
this
.
settings
.
wrapper
)
{
toToggle
=
toToggle
.
add
(
toToggle
.
parent
(
this
.
settings
.
wrapper
));
}
return
toToggle
;
},
defaultShowErrors
:
function
()
{
var
i
,
elements
;
for
(
i
=
0
;
this
.
errorList
[
i
];
i
++
)
{
var
error
=
this
.
errorList
[
i
];
if
(
this
.
settings
.
highlight
)
{
this
.
settings
.
highlight
.
call
(
this
,
error
.
element
,
this
.
settings
.
errorClass
,
this
.
settings
.
validClass
);
}
this
.
showLabel
(
error
.
element
,
error
.
message
);
}
if
(
this
.
errorList
.
length
)
{
this
.
toShow
=
this
.
toShow
.
add
(
this
.
containers
);
}
if
(
this
.
settings
.
success
)
{
for
(
i
=
0
;
this
.
successList
[
i
];
i
++
)
{
this
.
showLabel
(
this
.
successList
[
i
]);
}
}
if
(
this
.
settings
.
unhighlight
)
{
for
(
i
=
0
,
elements
=
this
.
validElements
();
elements
[
i
];
i
++
)
{
this
.
settings
.
unhighlight
.
call
(
this
,
elements
[
i
],
this
.
settings
.
errorClass
,
this
.
settings
.
validClass
);
}
}
this
.
toHide
=
this
.
toHide
.
not
(
this
.
toShow
);
this
.
hideErrors
();
this
.
addWrapper
(
this
.
toShow
).
show
();
},
validElements
:
function
()
{
return
this
.
currentElements
.
not
(
this
.
invalidElements
());
},
invalidElements
:
function
()
{
return
$
(
this
.
errorList
).
map
(
function
()
{
return
this
.
element
;
});
},
showLabel
:
function
(
element
,
message
)
{
if
(
$
(
element
).
is
(
'select'
)){
$
(
element
).
prev
(
'input'
).
addClass
(
'error-border-style'
);
}
else
if
(
$
(
element
).
is
(
'input'
)){
$
(
element
).
addClass
(
'error-border-style'
);
}
return
false
;
var
label
=
this
.
errorsFor
(
element
);
if
(
label
.
length
)
{
// refresh error/success class
label
.
removeClass
(
this
.
settings
.
validClass
).
addClass
(
this
.
settings
.
errorClass
);
// check if we have a generated label, replace the message then
if
(
label
.
attr
(
"generated"
))
{
label
.
hide
().
html
(
message
);
}
}
else
{
// create label
label
=
$
(
"<"
+
this
.
settings
.
errorElement
+
"/>"
)
.
attr
({
"for"
:
this
.
idOrName
(
element
),
generated
:
true
})
.
addClass
(
this
.
settings
.
errorClass
)
.
html
(
message
||
""
);
if
(
this
.
settings
.
wrapper
)
{
// make sure the element is visible, even in IE
// actually showing the wrapped element is handled elsewhere
label
=
label
.
hide
().
show
().
wrap
(
"<"
+
this
.
settings
.
wrapper
+
"/>"
).
parent
();
}
label
.
outerHTML
=
''
;
label
.
text
(
""
);
if
(
!
this
.
labelContainer
.
append
(
label
).
length
)
{
if
(
this
.
settings
.
errorPlacement
)
{
this
.
settings
.
errorPlacement
(
label
,
$
(
element
));
}
else
{
label
.
insertAfter
(
element
);
}
}
}
if
(
!
message
&&
this
.
settings
.
success
)
{
label
.
text
(
""
);
if
(
typeof
this
.
settings
.
success
===
"string"
)
{
label
.
addClass
(
this
.
settings
.
success
);
}
else
{
this
.
settings
.
success
(
label
,
element
);
}
}
this
.
toShow
=
this
.
toShow
.
add
(
''
);
},
errorsFor
:
function
(
element
)
{
var
name
=
this
.
idOrName
(
element
);
return
this
.
errors
().
filter
(
function
()
{
return
$
(
this
).
attr
(
'for'
)
===
name
;
});
},
idOrName
:
function
(
element
)
{
return
this
.
groups
[
element
.
name
]
||
(
this
.
checkable
(
element
)
?
element
.
name
:
element
.
id
||
element
.
name
);
},
validationTargetFor
:
function
(
element
)
{
// if radio/checkbox, validate first element in group instead
if
(
this
.
checkable
(
element
))
{
element
=
this
.
findByName
(
element
.
name
).
not
(
this
.
settings
.
ignore
)[
0
];
}
return
element
;
},
checkable
:
function
(
element
)
{
return
(
/radio|checkbox/i
).
test
(
element
.
type
);
},
findByName
:
function
(
name
)
{
return
$
(
this
.
currentForm
).
find
(
'[name="'
+
name
+
'"]'
);
},
getLength
:
function
(
value
,
element
)
{
switch
(
element
.
nodeName
.
toLowerCase
())
{
case
'select'
:
return
$
(
"option:selected"
,
element
).
length
;
case
'input'
:
if
(
this
.
checkable
(
element
))
{
return
this
.
findByName
(
element
.
name
).
filter
(
':checked'
).
length
;
}
}
return
value
.
length
;
},
depend
:
function
(
param
,
element
)
{
return
this
.
dependTypes
[
typeof
param
]
?
this
.
dependTypes
[
typeof
param
](
param
,
element
)
:
true
;
},
dependTypes
:
{
"boolean"
:
function
(
param
,
element
)
{
return
param
;
},
"string"
:
function
(
param
,
element
)
{
return
!!
$
(
param
,
element
.
form
).
length
;
},
"function"
:
function
(
param
,
element
)
{
return
param
(
element
);
}
},
optional
:
function
(
element
)
{
var
val
=
this
.
elementValue
(
element
);
return
!
$
.
validator
.
methods
.
required
.
call
(
this
,
val
,
element
)
&&
"dependency-mismatch"
;
},
startRequest
:
function
(
element
)
{
if
(
!
this
.
pending
[
element
.
name
])
{
this
.
pendingRequest
++
;
this
.
pending
[
element
.
name
]
=
true
;
}
},
stopRequest
:
function
(
element
,
valid
)
{
this
.
pendingRequest
--
;
// sometimes synchronization fails, make sure pendingRequest is never < 0
if
(
this
.
pendingRequest
<
0
)
{
this
.
pendingRequest
=
0
;
}
delete
this
.
pending
[
element
.
name
];
if
(
valid
&&
this
.
pendingRequest
===
0
&&
this
.
formSubmitted
&&
this
.
form
())
{
$
(
this
.
currentForm
).
submit
();
this
.
formSubmitted
=
false
;
}
else
if
(
!
valid
&&
this
.
pendingRequest
===
0
&&
this
.
formSubmitted
)
{
$
(
this
.
currentForm
).
triggerHandler
(
"invalid-form"
,
[
this
]);
this
.
formSubmitted
=
false
;
}
},
previousValue
:
function
(
element
)
{
return
$
.
data
(
element
,
"previousValue"
)
||
$
.
data
(
element
,
"previousValue"
,
{
old
:
null
,
valid
:
true
,
message
:
this
.
defaultMessage
(
element
,
"remote"
)
});
}
},
classRuleSettings
:
{
required
:
{
required
:
true
},
email
:
{
email
:
true
},
url
:
{
url
:
true
},
date
:
{
date
:
true
},
dateISO
:
{
dateISO
:
true
},
number
:
{
number
:
true
},
digits
:
{
digits
:
true
},
creditcard
:
{
creditcard
:
true
}
},
addClassRules
:
function
(
className
,
rules
)
{
if
(
className
.
constructor
===
String
)
{
this
.
classRuleSettings
[
className
]
=
rules
;
}
else
{
$
.
extend
(
this
.
classRuleSettings
,
className
);
}
},
classRules
:
function
(
element
)
{
var
rules
=
{};
var
classes
=
$
(
element
).
attr
(
'class'
);
if
(
classes
)
{
$
.
each
(
classes
.
split
(
' '
),
function
()
{
if
(
this
in
$
.
validator
.
classRuleSettings
)
{
$
.
extend
(
rules
,
$
.
validator
.
classRuleSettings
[
this
]);
}
});
}
return
rules
;
},
attributeRules
:
function
(
element
)
{
var
rules
=
{};
var
$element
=
$
(
element
);
for
(
var
method
in
$
.
validator
.
methods
)
{
var
value
;
// support for <input required> in both html5 and older browsers
if
(
method
===
'required'
)
{
value
=
$element
.
get
(
0
).
getAttribute
(
method
);
// Some browsers return an empty string for the required attribute
// and non-HTML5 browsers might have required="" markup
if
(
value
===
""
)
{
value
=
true
;
}
// force non-HTML5 browsers to return bool
value
=
!!
value
;
}
else
{
value
=
$element
.
attr
(
method
);
}
if
(
value
)
{
rules
[
method
]
=
value
;
}
else
if
(
$element
[
0
].
getAttribute
(
"type"
)
===
method
)
{
rules
[
method
]
=
true
;
}
}
// maxlength may be returned as -1, 2147483647 (IE) and 524288 (safari) for text inputs
if
(
rules
.
maxlength
&&
/-1|2147483647|524288/
.
test
(
rules
.
maxlength
))
{
delete
rules
.
maxlength
;
}
return
rules
;
},
metadataRules
:
function
(
element
)
{
if
(
!
$
.
metadata
)
{
return
{};
}
var
meta
=
$
.
data
(
element
.
form
,
'validator'
).
settings
.
meta
;
return
meta
?
$
(
element
).
metadata
()[
meta
]
:
$
(
element
).
metadata
();
},
staticRules
:
function
(
element
)
{
var
rules
=
{};
var
validator
=
$
.
data
(
element
.
form
,
'validator'
);
if
(
validator
.
settings
.
rules
)
{
rules
=
$
.
validator
.
normalizeRule
(
validator
.
settings
.
rules
[
element
.
name
])
||
{};
}
return
rules
;
},
normalizeRules
:
function
(
rules
,
element
)
{
// handle dependency check
$
.
each
(
rules
,
function
(
prop
,
val
)
{
// ignore rule when param is explicitly false, eg. required:false
if
(
val
===
false
)
{
delete
rules
[
prop
];
return
;
}
if
(
val
.
param
||
val
.
depends
)
{
var
keepRule
=
true
;
switch
(
typeof
val
.
depends
)
{
case
"string"
:
keepRule
=
!!
$
(
val
.
depends
,
element
.
form
).
length
;
break
;
case
"function"
:
keepRule
=
val
.
depends
.
call
(
element
,
element
);
break
;
}
if
(
keepRule
)
{
rules
[
prop
]
=
val
.
param
!==
undefined
?
val
.
param
:
true
;
}
else
{
delete
rules
[
prop
];
}
}
});
// evaluate parameters
$
.
each
(
rules
,
function
(
rule
,
parameter
)
{
rules
[
rule
]
=
$
.
isFunction
(
parameter
)
?
parameter
(
element
)
:
parameter
;
});
// clean number parameters
$
.
each
([
'minlength'
,
'maxlength'
,
'min'
,
'max'
],
function
()
{
if
(
rules
[
this
])
{
rules
[
this
]
=
Number
(
rules
[
this
]);
}
});
$
.
each
([
'rangelength'
,
'range'
],
function
()
{
if
(
rules
[
this
])
{
rules
[
this
]
=
[
Number
(
rules
[
this
][
0
]),
Number
(
rules
[
this
][
1
])];
}
});
if
(
$
.
validator
.
autoCreateRanges
)
{
// auto-create ranges
if
(
rules
.
min
&&
rules
.
max
)
{
rules
.
range
=
[
rules
.
min
,
rules
.
max
];
delete
rules
.
min
;
delete
rules
.
max
;
}
if
(
rules
.
minlength
&&
rules
.
maxlength
)
{
rules
.
rangelength
=
[
rules
.
minlength
,
rules
.
maxlength
];
delete
rules
.
minlength
;
delete
rules
.
maxlength
;
}
}
// To support custom messages in metadata ignore rule methods titled "messages"
if
(
rules
.
messages
)
{
delete
rules
.
messages
;
}
return
rules
;
},
// Converts a simple string to a {string: true} rule, e.g., "required" to {required:true}
normalizeRule
:
function
(
data
)
{
if
(
typeof
data
===
"string"
)
{
var
transformed
=
{};
$
.
each
(
data
.
split
(
/
\s
/
),
function
()
{
transformed
[
this
]
=
true
;
});
data
=
transformed
;
}
return
data
;
},
// http://docs.jquery.com/Plugins/Validation/Validator/addMethod
addMethod
:
function
(
name
,
method
,
message
)
{
$
.
validator
.
methods
[
name
]
=
method
;
$
.
validator
.
messages
[
name
]
=
message
!==
undefined
?
message
:
$
.
validator
.
messages
[
name
];
if
(
method
.
length
<
3
)
{
$
.
validator
.
addClassRules
(
name
,
$
.
validator
.
normalizeRule
(
name
));
}
},
methods
:
{
// http://docs.jquery.com/Plugins/Validation/Methods/required
required
:
function
(
value
,
element
,
param
)
{
// check if dependency is met
if
(
!
this
.
depend
(
param
,
element
))
{
return
"dependency-mismatch"
;
}
if
(
element
.
nodeName
.
toLowerCase
()
===
"select"
)
{
// could be an array for select-multiple or a string, both are fine this way
var
val
=
$
(
element
).
val
();
return
val
&&
val
.
length
>
0
;
}
if
(
this
.
checkable
(
element
))
{
return
this
.
getLength
(
value
,
element
)
>
0
;
}
return
$
.
trim
(
value
).
length
>
0
;
},
validate
:
function
()
{
return
true
;
},
// http://docs.jquery.com/Plugins/Validation/Methods/remote
remote
:
function
(
value
,
element
,
param
)
{
if
(
this
.
optional
(
element
))
{
return
"dependency-mismatch"
;
}
var
previous
=
this
.
previousValue
(
element
);
if
(
!
this
.
settings
.
messages
[
element
.
name
])
{
this
.
settings
.
messages
[
element
.
name
]
=
{};
}
previous
.
originalMessage
=
this
.
settings
.
messages
[
element
.
name
].
remote
;
this
.
settings
.
messages
[
element
.
name
].
remote
=
previous
.
message
;
param
=
typeof
param
===
"string"
&&
{
url
:
param
}
||
param
;
if
(
this
.
pending
[
element
.
name
])
{
return
"pending"
;
}
if
(
previous
.
old
===
value
)
{
return
previous
.
valid
;
}
previous
.
old
=
value
;
var
validator
=
this
;
this
.
startRequest
(
element
);
var
data
=
{};
data
[
element
.
name
]
=
value
;
$
.
ajax
(
$
.
extend
(
true
,
{
url
:
param
,
mode
:
"abort"
,
port
:
"validate"
+
element
.
name
,
dataType
:
"json"
,
data
:
data
,
success
:
function
(
response
)
{
validator
.
settings
.
messages
[
element
.
name
].
remote
=
previous
.
originalMessage
;
var
valid
=
response
===
true
||
response
===
"true"
;
if
(
valid
)
{
var
submitted
=
validator
.
formSubmitted
;
validator
.
prepareElement
(
element
);
validator
.
formSubmitted
=
submitted
;
validator
.
successList
.
push
(
element
);
delete
validator
.
invalid
[
element
.
name
];
validator
.
showErrors
();
}
else
{
var
errors
=
{};
var
message
=
response
||
validator
.
defaultMessage
(
element
,
"remote"
);
errors
[
element
.
name
]
=
previous
.
message
=
$
.
isFunction
(
message
)
?
message
(
value
)
:
message
;
validator
.
invalid
[
element
.
name
]
=
true
;
validator
.
showErrors
(
errors
);
}
previous
.
valid
=
valid
;
validator
.
stopRequest
(
element
,
valid
);
}
},
param
));
return
"pending"
;
},
// http://docs.jquery.com/Plugins/Validation/Methods/minlength
minlength
:
function
(
value
,
element
,
param
)
{
var
length
=
$
.
isArray
(
value
)
?
value
.
length
:
this
.
getLength
(
$
.
trim
(
value
),
element
);
return
this
.
optional
(
element
)
||
length
>=
param
;
},
// http://docs.jquery.com/Plugins/Validation/Methods/maxlength
maxlength
:
function
(
value
,
element
,
param
)
{
var
length
=
$
.
isArray
(
value
)
?
value
.
length
:
this
.
getLength
(
$
.
trim
(
value
),
element
);
return
this
.
optional
(
element
)
||
length
<=
param
;
},
// http://docs.jquery.com/Plugins/Validation/Methods/rangelength
rangelength
:
function
(
value
,
element
,
param
)
{
var
length
=
$
.
isArray
(
value
)
?
value
.
length
:
this
.
getLength
(
$
.
trim
(
value
),
element
);
return
this
.
optional
(
element
)
||
(
length
>=
param
[
0
]
&&
length
<=
param
[
1
]
);
},
// http://docs.jquery.com/Plugins/Validation/Methods/min
min
:
function
(
value
,
element
,
param
)
{
return
this
.
optional
(
element
)
||
value
>=
param
;
},
// http://docs.jquery.com/Plugins/Validation/Methods/max
max
:
function
(
value
,
element
,
param
)
{
return
this
.
optional
(
element
)
||
value
<=
param
;
},
// http://docs.jquery.com/Plugins/Validation/Methods/range
range
:
function
(
value
,
element
,
param
)
{
return
this
.
optional
(
element
)
||
(
value
>=
param
[
0
]
&&
value
<=
param
[
1
]
);
},
// http://docs.jquery.com/Plugins/Validation/Methods/email
email
:
function
(
value
,
element
)
{
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
return
this
.
optional
(
element
)
||
/^
((([
a-z
]
|
\d
|
[
!#
\$
%&'
\*\+\-\/
=
\?\^
_`{
\|
}~
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
+
(\.([
a-z
]
|
\d
|
[
!#
\$
%&'
\*\+\-\/
=
\?\^
_`{
\|
}~
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
+
)
*
)
|
((\x
22
)((((\x
20|
\x
09
)
*
(\x
0d
\x
0a
))?(\x
20|
\x
09
)
+
)?(([\x
01-
\x
08
\x
0b
\x
0c
\x
0e-
\x
1f
\x
7f
]
|
\x
21|
[\x
23-
\x
5b
]
|
[\x
5d-
\x
7e
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(\\([\x
01-
\x
09
\x
0b
\x
0c
\x
0d-
\x
7f
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
]))))
*
(((\x
20|
\x
09
)
*
(\x
0d
\x
0a
))?(\x
20|
\x
09
)
+
)?(\x
22
)))
@
((([
a-z
]
|
\d
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(([
a-z
]
|
\d
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
*
([
a-z
]
|
\d
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])))\.)
+
(([
a-z
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(([
a-z
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
*
([
a-z
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])))
$/i
.
test
(
value
);
},
// http://docs.jquery.com/Plugins/Validation/Methods/url
url
:
function
(
value
,
element
)
{
// contributed by Scott Gonzalez: http://projects.scottsplayground.com/iri/
return
this
.
optional
(
element
)
||
/^
(
https
?
|ftp
)
:
\/\/(((([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(
%
[\d
a-f
]{2})
|
[
!
\$
&'
\(\)\*\+
,;=
]
|:
)
*@
)?(((\d
|
[
1-9
]\d
|1
\d\d
|2
[
0-4
]\d
|25
[
0-5
])\.(\d
|
[
1-9
]\d
|1
\d\d
|2
[
0-4
]\d
|25
[
0-5
])\.(\d
|
[
1-9
]\d
|1
\d\d
|2
[
0-4
]\d
|25
[
0-5
])\.(\d
|
[
1-9
]\d
|1
\d\d
|2
[
0-4
]\d
|25
[
0-5
]))
|
((([
a-z
]
|
\d
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(([
a-z
]
|
\d
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
*
([
a-z
]
|
\d
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])))\.)
+
(([
a-z
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(([
a-z
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
*
([
a-z
]
|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])))\.?)(
:
\d
*
)?)(\/((([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(
%
[\d
a-f
]{2})
|
[
!
\$
&'
\(\)\*\+
,;=
]
|:|@
)
+
(\/(([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(
%
[\d
a-f
]{2})
|
[
!
\$
&'
\(\)\*\+
,;=
]
|:|@
)
*
)
*
)?)?(\?((([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(
%
[\d
a-f
]{2})
|
[
!
\$
&'
\(\)\*\+
,;=
]
|:|@
)
|
[\u
E000-
\u
F8FF
]
|
\/
|
\?)
*
)?(\#((([
a-z
]
|
\d
|-|
\.
|_|~|
[\u
00A0-
\u
D7FF
\u
F900-
\u
FDCF
\u
FDF0-
\u
FFEF
])
|
(
%
[\d
a-f
]{2})
|
[
!
\$
&'
\(\)\*\+
,;=
]
|:|@
)
|
\/
|
\?)
*
)?
$/i
.
test
(
value
);
},
// http://docs.jquery.com/Plugins/Validation/Methods/date
date
:
function
(
value
,
element
)
{
return
this
.
optional
(
element
)
||
!
/Invalid|NaN/
.
test
(
new
Date
(
value
));
},
// http://docs.jquery.com/Plugins/Validation/Methods/dateISO
dateISO
:
function
(
value
,
element
)
{
return
this
.
optional
(
element
)
||
/^
\d{4}[\/\-]\d{1,2}[\/\-]\d{1,2}
$/
.
test
(
value
);
},
// http://docs.jquery.com/Plugins/Validation/Methods/number
number
:
function
(
value
,
element
)
{
return
this
.
optional
(
element
)
||
/^-
?(?:\d
+|
\d{1,3}(?:
,
\d{3})
+
)?(?:\.\d
+
)?
$/
.
test
(
value
);
},
// http://docs.jquery.com/Plugins/Validation/Methods/digits
digits
:
function
(
value
,
element
)
{
return
this
.
optional
(
element
)
||
/^
\d
+$/
.
test
(
value
);
},
// http://docs.jquery.com/Plugins/Validation/Methods/creditcard
// based on http://en.wikipedia.org/wiki/Luhn
creditcard
:
function
(
value
,
element
)
{
if
(
this
.
optional
(
element
))
{
return
"dependency-mismatch"
;
}
// accept only spaces, digits and dashes
if
(
/
[^
0-9
\-]
+/
.
test
(
value
))
{
return
false
;
}
var
nCheck
=
0
,
nDigit
=
0
,
bEven
=
false
;
value
=
value
.
replace
(
/
\D
/g
,
""
);
for
(
var
n
=
value
.
length
-
1
;
n
>=
0
;
n
--
)
{
var
cDigit
=
value
.
charAt
(
n
);
nDigit
=
parseInt
(
cDigit
,
10
);
if
(
bEven
)
{
if
((
nDigit
*=
2
)
>
9
)
{
nDigit
-=
9
;
}
}
nCheck
+=
nDigit
;
bEven
=
!
bEven
;
}
return
(
nCheck
%
10
)
===
0
;
},
// http://docs.jquery.com/Plugins/Validation/Methods/equalTo
equalTo
:
function
(
value
,
element
,
param
)
{
// bind to the blur event of the target in order to revalidate whenever the target field is updated
// TODO find a way to bind the event just once, avoiding the unbind-rebind overhead
var
target
=
$
(
param
);
if
(
this
.
settings
.
onfocusout
)
{
target
.
unbind
(
".validate-equalTo"
).
bind
(
"blur.validate-equalTo"
,
function
()
{
$
(
element
).
valid
();
});
}
return
value
===
target
.
val
();
}
}
});
// deprecated, use $.validator.format instead
$
.
format
=
$
.
validator
.
format
;
}(
jQuery
));
// ajax mode: abort
// usage: $.ajax({ mode: "abort"[, port: "uniqueport"]});
// if mode:"abort" is used, the previous request on that port (port can be undefined) is aborted via XMLHttpRequest.abort()
(
function
(
$
)
{
var
pendingRequests
=
{};
// Use a prefilter if available (1.5+)
if
(
$
.
ajaxPrefilter
)
{
$
.
ajaxPrefilter
(
function
(
settings
,
_
,
xhr
)
{
var
port
=
settings
.
port
;
if
(
settings
.
mode
===
"abort"
)
{
if
(
pendingRequests
[
port
])
{
pendingRequests
[
port
].
abort
();
}
pendingRequests
[
port
]
=
xhr
;
}
});
}
else
{
// Proxy ajax
var
ajax
=
$
.
ajax
;
$
.
ajax
=
function
(
settings
)
{
var
mode
=
(
"mode"
in
settings
?
settings
:
$
.
ajaxSettings
).
mode
,
port
=
(
"port"
in
settings
?
settings
:
$
.
ajaxSettings
).
port
;
if
(
mode
===
"abort"
)
{
if
(
pendingRequests
[
port
])
{
pendingRequests
[
port
].
abort
();
}
return
(
pendingRequests
[
port
]
=
ajax
.
apply
(
this
,
arguments
));
}
return
ajax
.
apply
(
this
,
arguments
);
};
}
}(
jQuery
));
// provides cross-browser focusin and focusout events
// IE has native support, in other browsers, use event caputuring (neither bubbles)
// provides delegate(type: String, delegate: Selector, handler: Callback) plugin for easier event delegation
// handler is only called when $(event.target).is(delegate), in the scope of the jquery-object for event.target
(
function
(
$
)
{
// only implement if not provided by jQuery core (since 1.4)
// TODO verify if jQuery 1.4's implementation is compatible with older jQuery special-event APIs
if
(
!
jQuery
.
event
.
special
.
focusin
&&
!
jQuery
.
event
.
special
.
focusout
&&
document
.
addEventListener
)
{
$
.
each
({
focus
:
'focusin'
,
blur
:
'focusout'
},
function
(
original
,
fix
)
{
$
.
event
.
special
[
fix
]
=
{
setup
:
function
()
{
this
.
addEventListener
(
original
,
handler
,
true
);
},
teardown
:
function
()
{
this
.
removeEventListener
(
original
,
handler
,
true
);
},
handler
:
function
(
e
)
{
var
args
=
arguments
;
args
[
0
]
=
$
.
event
.
fix
(
e
);
args
[
0
].
type
=
fix
;
return
$
.
event
.
handle
.
apply
(
this
,
args
);
}
};
function
handler
(
e
)
{
e
=
$
.
event
.
fix
(
e
);
e
.
type
=
fix
;
return
$
.
event
.
handle
.
call
(
this
,
e
);
}
});
}
$
.
extend
(
$
.
fn
,
{
validateDelegate
:
function
(
delegate
,
type
,
handler
)
{
return
this
.
bind
(
type
,
function
(
event
)
{
var
target
=
$
(
event
.
target
);
if
(
target
.
is
(
delegate
))
{
return
handler
.
apply
(
target
,
arguments
);
}
});
}
});
}(
jQuery
));
}));
\ No newline at end of file
lib/web/mage/validation.js
View file @
ccdf1fce
...
...
@@ -9,6 +9,7 @@ define([
'mageUtils'
,
'jquery-ui-modules/widget'
,
'jquery/validate'
,
'jquery/validates'
,
'mage/translate'
],
function
(
$
,
moment
,
utils
)
{
'use strict'
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment