Skip to content

Commit

Permalink
Swtich input types according to selected country
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagogsr committed Mar 10, 2017
1 parent 7742c52 commit ea7473e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
21 changes: 9 additions & 12 deletions assets/js/frontend/frontend.js
Expand Up @@ -112,35 +112,32 @@ jQuery( function( $ ) {
},

maskBilling: function() {
$( '#billing_phone, #billing_cellphone' )
.focusout( wc_ecfb_frontend.maskPhone )
.trigger( 'focusout' );
wc_ecfb_frontend.maskPhone( '#billing_phone, #billing_cellphone' );
$( '#billing_birthdate' ).mask( '00/00/0000' );
$( '#billing_postcode' ).mask( '00000-000' );
$( '#billing_phone, #billing_cellphone, #billing_birthdate, #billing_postcode' ).attr( 'type', 'tel' );
},

unmaskBilling: function() {
$( '#billing_phone, #billing_cellphone, #billing_birthdate, #billing_postcode' ).unmask();
$( '#billing_phone, #billing_cellphone, #billing_birthdate, #billing_postcode' ).unmask().attr( 'type', 'text' );
},

maskShipping: function() {
$( '#shipping_postcode' ).mask( '00000-000' );
$( '#shipping_postcode' ).mask( '00000-000' ).attr( 'type', 'tel' );
},

unmaskShipping: function() {
$( '#shipping_postcode' ).unmask();
$( '#shipping_postcode' ).unmask().attr( 'type', 'text' );
},

maskGeneral: function() {
$( '#billing_cpf, #credit-card-cpf' ).mask( '000.000.000-00' );
$( '#billing_cnpj' ).mask( '00.000.000/0000-00' );
$( '#credit-card-phone' )
.focusout( wc_ecfb_frontend.maskPhone )
.trigger( 'focusout' );
wc_ecfb_frontend.maskPhone( '#credit-card-phone' );
},

maskPhone: function() {
var element = $( this ),
maskPhone: function(selector) {
var $element = $(selector),
MaskBehavior = function(val) {
return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
},
Expand All @@ -150,7 +147,7 @@ jQuery( function( $ ) {
}
};

element.mask(MaskBehavior, maskOptions);
$element.mask(MaskBehavior, maskOptions);
},

emailCheck: function() {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/frontend/frontend.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions includes/class-wc-ecfb-front-end.php
Expand Up @@ -215,8 +215,7 @@ public function checkout_billing_fields( $fields ) {
'placeholder' => _x( 'Birthdate', 'placeholder', 'woocommerce-extra-checkout-fields-for-brazil' ),
'class' => array( 'form-row-first' ),
'clear' => false,
'required' => true,
'type' => 'tel'
'required' => true
);

$new_fields['billing_sex'] = array(
Expand All @@ -241,7 +240,6 @@ public function checkout_billing_fields( $fields ) {
if ( isset( $fields['billing_postcode'] ) ) {
$new_fields['billing_postcode'] = $fields['billing_postcode'];
$new_fields['billing_postcode']['class'] = array( 'form-row-last', 'address-field' );
$new_fields['billing_postcode']['type'] = 'tel';
}

if ( isset( $fields['billing_address_1'] ) ) {
Expand Down Expand Up @@ -288,15 +286,13 @@ public function checkout_billing_fields( $fields ) {
$new_fields['billing_phone'] = $fields['billing_phone'];
$new_fields['billing_phone']['class'] = array( 'form-row-first' );
$new_fields['billing_phone']['clear'] = false;
$new_fields['billing_phone']['type'] = 'tel';
}

$new_fields['billing_cellphone'] = array(
'label' => __( 'Cell Phone', 'woocommerce-extra-checkout-fields-for-brazil' ),
'placeholder' => _x( 'Cell Phone', 'placeholder', 'woocommerce-extra-checkout-fields-for-brazil' ),
'class' => array( 'form-row-last' ),
'clear' => true,
'type' => 'tel'
'clear' => true
);

if ( isset( $fields['billing_email'] ) ) {
Expand All @@ -309,7 +305,6 @@ public function checkout_billing_fields( $fields ) {
} else {
if ( isset( $fields['billing_phone'] ) ) {
$new_fields['billing_phone'] = $fields['billing_phone'];
$new_fields['billing_phone']['type'] = 'tel';
$new_fields['billing_state']['class'] = array( 'form-row-wide' );
$new_fields['billing_state']['clear'] = true;
}
Expand Down Expand Up @@ -360,7 +355,6 @@ public function checkout_shipping_fields( $fields ) {
if ( isset( $fields['shipping_postcode'] ) ) {
$new_fields['shipping_postcode'] = $fields['shipping_postcode'];
$new_fields['shipping_postcode']['class'] = array( 'form-row-last', 'address-field' );
$new_fields['shipping_postcode']['type'] = 'tel';
}

if ( isset( $fields['shipping_address_1'] ) ) {
Expand Down

0 comments on commit ea7473e

Please sign in to comment.