Skip to content

Commit

Permalink
Merge pull request #1858 from raftaar1191/issues-1050
Browse files Browse the repository at this point in the history
Issues 1050
  • Loading branch information
Devin Walker committed Jul 14, 2017
2 parents 6ee9252 + 37da3c4 commit f42d795
Show file tree
Hide file tree
Showing 12 changed files with 1,098 additions and 104 deletions.
20 changes: 9 additions & 11 deletions assets/js/admin/admin-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,13 @@ jQuery.noConflict();

state_wrap.find( '*' ).not( '.order-data-address-line' ).remove();

if ( 'nostates' == response ) {
state_wrap.append( '<input type="text" name="give-payment-address[0][state]" value="" class="give-edit-toggles medium-text"/>' );
} else {
state_wrap.append( response );
state_wrap.find( 'select' ).chosen();
}
if( typeof ( response.states_found ) != undefined && true == response.states_found ) {
state_wrap.append( response.data );
state_wrap.find( 'select' ).chosen();
} else {
state_wrap.append( '<input type="text" name="give-payment-address[0][state]" value="" class="give-edit-toggles medium-text"/>' );
}
} );

return false;
} );

Expand Down Expand Up @@ -922,13 +921,12 @@ jQuery.noConflict();
field_name: 'customerinfo[state]'
};
$.post( ajaxurl, data, function( response ) {
if ( 'nostates' === response ) {
$( ':input[name="customerinfo[state]"]' ).replaceWith( '<input type="text" name="' + data.field_name + '" value="" class="give-edit-toggles medium-text"/>' );
if( typeof ( response.states_found ) != undefined && true == response.states_found ) {
$( ':input[name="customerinfo[state]"]' ).replaceWith( response.data );
} else {
$( ':input[name="customerinfo[state]"]' ).replaceWith( response );
$( ':input[name="customerinfo[state]"]' ).replaceWith( '<input type="text" name="' + data.field_name + '" value="" class="give-edit-toggles medium-text"/>' );
}
} );

return false;
} );
},
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin/admin-scripts.min.js

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions assets/js/frontend/give-checkout-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ jQuery(function ($) {
withCredentials: true
},
success : function (response) {
if ('nostates' == response) {
var text_field = '<input type="text" id="card_state" name="card_state" class="cart-state give-input required" value=""/>';
$form.find('input[name="card_state"], select[name="card_state"]').replaceWith(text_field);
if( typeof ( response.states_found ) != undefined && true == response.states_found ) {
$form.find('input[name="card_state"], select[name="card_state"]').replaceWith( response.data );
} else {
var text_field = '<input type="text" id="card_state" name="card_state" class="cart-state give-input required" value=""/>';
$form.find('input[name="card_state"], select[name="card_state"]').replaceWith(text_field);
}

// Check if user want to show the feilds or not.
if( typeof ( response.show_field ) != undefined && true == response.show_field ) {
$form.find( 'p#give-card-state-wrap' ).removeClass( 'give-hidden' );
} else {
$form.find('input[name="card_state"], select[name="card_state"]').replaceWith(response);
$form.find( 'p#give-card-state-wrap' ).addClass( 'give-hidden' );
}

doc.trigger('give_checkout_billing_address_updated', [response, $form.attr('id')]);
}
}).fail(function (data) {
Expand Down
2 changes: 1 addition & 1 deletion assets/js/frontend/give-checkout-global.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion assets/js/frontend/give.all.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion includes/admin/donors/donors.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ function give_donor_view( $donor ) {
<?php
} else {
?>
<input type="text" size="6" data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-input info-item" placeholder="<?php esc_attr_e( 'State / Province', 'give' ); ?>" />
<input type="text" size="6" data-key="state" name="customerinfo[state]" id="card_state" class="card_state give-input info-item" placeholder="<?php esc_attr_e( 'State / Province / County', 'give' ); ?>" />
<?php
}
?>
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/payments/view-payment-details.php
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@
?>
</div>
<div id="give-order-address-state-wrap">
<label for="give-payment-address-state" class="order-data-address-line"><?php esc_html_e( 'State / Province:', 'give' ); ?></label>
<label for="give-payment-address-state" class="order-data-address-line"><?php esc_html_e( 'State / Province / County:', 'give' ); ?></label>
<?php
$states = give_get_states( $address['country'] );
if ( ! empty( $states ) ) {
Expand Down
48 changes: 31 additions & 17 deletions includes/ajax-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,35 +192,49 @@ function give_ajax_get_form_title() {
* @return void
*/
function give_ajax_get_states_field() {
$states_found = false;
$show_field = true;
// Get the Country code from the $_POST.
$country = sanitize_text_field( $_POST['country'] );

if ( empty( $_POST['country'] ) ) {
$_POST['country'] = give_get_country();
// Get the field name from the $_POST.
$field_name = sanitize_text_field( $_POST['field_name'] );

if ( empty( $country ) ) {
$country = give_get_country();
}
$states = give_get_states( $_POST['country'] );

$states = give_get_states( $country );
if ( ! empty( $states ) ) {

$args = array(
'name' => $_POST['field_name'],
'id' => $_POST['field_name'],
'class' => $_POST['field_name'] . ' give-select',
'options' => give_get_states( $_POST['country'] ),
'name' => $field_name,
'id' => $field_name,
'class' => $field_name . ' give-select',
'options' => $states,
'show_option_all' => false,
'show_option_none' => false,
);

$response = Give()->html->select( $args );

$data = Give()->html->select( $args );
$states_found = true;
} else {
$data = 'nostates';

$response = 'nostates';
}

echo $response;
// Get the country list that does not have any states init.
$no_states_country = give_no_states_country_list();

give_die();
// Check if $country code exists in the array key.
if ( array_key_exists( $country, $no_states_country ) ) {
$show_field = false;
}
}
$response = array(
'success' => true,
'states_found' => $states_found,
'show_field' => $show_field,
'data' => $data,
);
wp_send_json( $response );
}

add_action( 'wp_ajax_give_get_states', 'give_ajax_get_states_field' );
add_action( 'wp_ajax_nopriv_give_get_states', 'give_ajax_get_states_field' );

Expand Down
Loading

0 comments on commit f42d795

Please sign in to comment.