File tree 3 files changed +16
-27
lines changed
app/code/Magento/CheckoutAgreements/view/frontend/web
3 files changed +16
-27
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,8 @@ define(
12
12
function ( $ ) {
13
13
'use strict' ;
14
14
var checkoutConfig = window . checkoutConfig ,
15
- agreementsConfig = checkoutConfig ? checkoutConfig . checkoutAgreements : { } ;
16
-
17
- var agreementsInputPath = '.payment-method._active div.checkout-agreements input' ;
15
+ agreementsConfig = checkoutConfig ? checkoutConfig . checkoutAgreements : { } ,
16
+ agreementsInputPath = '.payment-method._active div.checkout-agreements input' ;
18
17
19
18
return {
20
19
/**
@@ -23,26 +22,11 @@ define(
23
22
* @returns {boolean }
24
23
*/
25
24
validate : function ( ) {
26
- if ( ! agreementsConfig . isEnabled ) {
27
- return true ;
28
- }
29
-
30
- if ( $ ( agreementsInputPath ) . length == 0 ) {
25
+ if ( ! agreementsConfig . isEnabled || $ ( agreementsInputPath ) . length == 0 ) {
31
26
return true ;
32
27
}
33
28
34
- return $ ( '#co-payment-form' ) . validate ( {
35
- errorClass : 'mage-error' ,
36
- errorElement : 'div' ,
37
- meta : 'validate' ,
38
- errorPlacement : function ( error , element ) {
39
- var errorPlacement = element ;
40
- if ( element . is ( ':checkbox' ) || element . is ( ':radio' ) ) {
41
- errorPlacement = element . siblings ( 'label' ) . last ( ) ;
42
- }
43
- errorPlacement . after ( error ) ;
44
- }
45
- } ) . element ( agreementsInputPath ) ;
29
+ return $ . validator . validateSingleElement ( agreementsInputPath , { errorElement : 'div' } ) ;
46
30
}
47
31
}
48
32
}
Original file line number Diff line number Diff line change 8
8
< div class ="checkout-agreements " data-bind ="visible: isVisible ">
9
9
<!-- ko foreach: agreements -->
10
10
<!-- ko if: ($parent.isAgreementRequired($data)) -->
11
- < div class ="checkout-agreement ">
12
- < input type ="checkbox "
11
+ < div class ="checkout-agreement required ">
12
+ < input type ="checkbox " class =" required-entry "
13
13
data-bind ="attr: {
14
14
'id': 'agreement_' + agreementId,
15
15
'name': 'agreement[' + agreementId + ']',
16
16
'value': agreementId
17
- } "
18
- data-validate ="{required:true} " />
17
+ } "/>
19
18
< label data-bind ="attr: {'for': 'agreement_' + agreementId} ">
20
19
< button type ="button "
21
20
class ="action action-show "
Original file line number Diff line number Diff line change 1441
1441
* Validate single element.
1442
1442
*
1443
1443
* @param {Element } element
1444
+ * @param {Object } config
1444
1445
* @returns {* }
1445
1446
*/
1446
- $ . validator . validateSingleElement = function ( element ) {
1447
+ $ . validator . validateSingleElement = function ( element , config ) {
1447
1448
var errors = { } ,
1448
1449
valid = true ,
1449
1450
validateConfig = {
1450
1451
errorElement : 'label' ,
1451
1452
ignore : '.ignore-validate'
1452
1453
} ,
1453
- form , validator , classes ;
1454
+ form , validator , classes , elementValue ;
1454
1455
1456
+ $ . extend ( validateConfig , config ) ;
1455
1457
element = $ ( element ) . not ( validateConfig . ignore ) ;
1456
1458
1457
1459
if ( ! element . length ) {
1475
1477
validator . toShow = validator . toHide = $ ( [ ] ) ;
1476
1478
1477
1479
$ . each ( classes , $ . proxy ( function ( i , className ) {
1478
- if ( this . methods [ className ] && ! this . methods [ className ] ( element . val ( ) , element . get ( 0 ) ) ) {
1480
+ elementValue = element . val ( ) ;
1481
+ if ( element . is ( ':checkbox' ) || element . is ( ':radio' ) ) {
1482
+ elementValue = element . is ( ':checked' ) || null ;
1483
+ }
1484
+ if ( this . methods [ className ] && ! this . methods [ className ] ( elementValue , element . get ( 0 ) ) ) {
1479
1485
valid = false ;
1480
1486
errors [ element . get ( 0 ) . name ] = this . messages [ className ] ;
1481
1487
validator . invalid [ element . get ( 0 ) . name ] = true ;
You can’t perform that action at this time.
0 commit comments