Home Forums Front-end Issues Add class to select2 field via Javascript


Add class to select2 field via Javascript

  • I want to add a class to all select2 fields in a frontend form. I know this is done bij Javascript but I just don’t know what it is. Below I have the code for date and time pickers and stuff. Could someone provide me the add-on for select2 fields?

    // Customization to booking datepicker
    function yl_add_acf_field_class_via_javascript() {
    	<script type="text/javascript">
    	(function($) {
    		// Check ACF
    		if(typeof acf === 'undefined')
    		// Date picker & Google Maps compatibility
    		$('.acf-google-map, .acf-date-picker input.input, .acf-time-picker input.input').addClass('uk-input');
    		// Clean errors on submission
    		acf.addAction('validation_begin', function($form){
    		// Add alert alert-danger & move below field
    		acf.addAction('invalid_field', function(field){
    			field.$el.find('.acf-notice.-error').addClass('uk-alert uk-alert-danger').insertAfter(field.$el.find('.acf-input'));
    add_action('acf/input/admin_footer', 'yl_add_acf_field_class_via_javascript');
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.