Skip to content
This repository was archived by the owner on Nov 6, 2019. It is now read-only.

Commit ca31be7

Browse files
committed
Added option to load and enable select2 in ticket registration form
We can remove this once select2 is added to the core. By default it will not be loaded or enabled, an option to enable it is also added.
1 parent 265ad90 commit ca31be7

63 files changed

Lines changed: 12901 additions & 5 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

admin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,5 +578,15 @@ window.camptix = window.camptix || { models: {}, views: {}, collections: {} };
578578
);
579579
} );
580580

581+
/**
582+
* Select2 for dropdowns rendered by tix page
583+
*/
584+
$( document ).ready( function() {
585+
if( ! $.fn.hasOwnProperty( 'select2' ) ){
586+
return;
587+
}
588+
$( '.tix-setup-form select' ).select2();
589+
});
590+
581591
});
582592
}(jQuery));

camptix.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ var docCookies={getItem:function(e){return decodeURIComponent(document.cookie.re
226226
}
227227
};
228228

229-
$( document ).ready( lazyLoad.init )
229+
$( document ).ready( lazyLoad.init );
230+
231+
232+
/**
233+
* Use select2 for dropdown.
234+
*/
235+
$( document ).ready( function loadSelect2Country() {
236+
if( ! tix.length || ! $.fn.hasOwnProperty( 'select2' ) )
237+
return;
238+
$( '#tix .tix-select2-enabled select' ).select2();
239+
})
230240

231241
}(jQuery));

camptix.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -470,9 +470,18 @@ function enqueue_scripts() {
470470
'enterEmail' => __( 'Please enter the e-mail addresses in the forms above.', 'camptix' ),
471471
'ajaxURL' => admin_url( 'admin-ajax.php' ),
472472
) );
473-
474473
// Let's play by the rules and print this in the <head> section.
475474
wp_enqueue_style( 'camptix' );
475+
476+
477+
if ( (bool) $this->options['select2_enabled'] ) {
478+
wp_register_style( 'select2', plugins_url( '/external/select2/css/select2.min.css', __FILE__ ), array(), $this->version );
479+
wp_register_script( 'select2', plugins_url( '/external/select2/js/select2.min.js', __FILE__ ), array(), $this->version );
480+
481+
wp_enqueue_style( 'select2' );
482+
wp_enqueue_script( 'select2' );
483+
}
484+
476485
}
477486

478487
function admin_enqueue_scripts() {
@@ -1493,8 +1502,11 @@ function menu_setup_controls() {
14931502
$this->add_settings_field_helper( 'currency', __( 'Currency', 'camptix' ), 'field_currency' );
14941503

14951504
$this->add_settings_field_helper( 'refunds_enabled', __( 'Enable Refunds', 'camptix' ), 'field_enable_refunds', false,
1496-
__( "This will allows your customers to refund their tickets purchase by filling out a simple refund form.", 'camptix' )
1505+
__( "This will allow your customers to refund their tickets purchase by filling out a simple refund form.", 'camptix' )
14971506
);
1507+
$this->add_settings_field_helper( 'select2_enabled', __( 'Enable Select2', 'camptix' ), 'field_enable_select2', false,
1508+
__( "This will render all the dropdown answers as a searchable dropdown instead of normal select dropdown", 'camptix' )
1509+
);
14981510

14991511
break;
15001512
case 'payment':
@@ -1621,7 +1633,7 @@ function validate_options( $input ) {
16211633
if ( isset( $input['refunds_date_end'], $input['refunds_enabled'] ) && (bool) $input['refunds_enabled'] && strtotime( $input['refunds_date_end'] ) )
16221634
$output['refunds_date_end'] = $input['refunds_date_end'];
16231635

1624-
$yesno_fields = array( 'refunds_enabled' );
1636+
$yesno_fields = array( 'refunds_enabled', 'select2_enabled' );
16251637

16261638
// Beta features checkboxes
16271639
if ( $this->beta_features_enabled )
@@ -1766,6 +1778,17 @@ function field_enable_refunds( $args ) {
17661778
<?php
17671779
}
17681780

1781+
function field_enable_select2( $args ) {?>
1782+
<div id="tix-select2-enabled-radios">
1783+
<label class="tix-yes-no description"><input type="radio" name="<?php echo esc_attr( $args['name'] ); ?>" value="1" <?php checked( $args['value'], true ); ?>> <?php _e( 'Yes', 'camptix' ); ?></label>
1784+
<label class="tix-yes-no description"><input type="radio" name="<?php echo esc_attr( $args['name'] ); ?>" value="0" <?php checked( $args['value'], false ); ?>> <?php _e( 'No', 'camptix' ); ?></label>
1785+
</div>
1786+
<?php if ( isset( $args['description'] ) ) : ?>
1787+
<p class="description"><?php echo wp_kses_post( $args['description'] ); ?></p>
1788+
<?php endif; ?>
1789+
<?php
1790+
}
1791+
17691792
/**
17701793
* The currency field for the Settings API.
17711794
*/
@@ -5480,7 +5503,8 @@ function form_attendee_info() {
54805503
$questions = $this->get_sorted_questions( $ticket->ID );
54815504
?>
54825505
<input type="hidden" name="tix_attendee_info[<?php echo esc_attr( $i ); ?>][ticket_id]" value="<?php echo intval( $ticket->ID ); ?>" />
5483-
<table class="tix_tickets_table tix-attendee-form">
5506+
<table class="tix_tickets_table tix-attendee-form <?php echo ( isset($this->options['select2_enabled']) && (bool) ( $this->options['select2_enabled'] ) ) ?
5507+
'tix-select2-enabled' : '' ?>">
54845508
<tbody>
54855509
<tr>
54865510
<th colspan="2">

0 commit comments

Comments
 (0)