• Resolved tripflex

    (@tripflex)


    This is actually related to how the API handles the output of radio/enum fields, but there is code in wp-content/plugins/wp-all-import/classes/api.php that outputs the enum fields, specifically setting this:

    
    <input type="radio" id="<?php echo sanitize_title($params['field_name']); ?>_<?php echo $key; ?>" class="switcher" name="<?php echo $params['field_name']; ?>" value="<?php echo $key; ?>" <?php echo $key == $params['field_value'] ? 'checked="checked"': '' ?>/>
    

    What ends up happening, is if the $key is something like 5'10" - 5'12" there’s numerous javascript errors

    
    Uncaught Error: Syntax error, unrecognized expression: .switcher-target-wpjm_fe_addon_jobs_job_radio_test_5'1" - 5'10"
    

    Due to /wp-content/plugins/wp-all-import/static/js/admin.js that has this code:

    
        // swither show/hide logic
    	$('input.switcher').live('change', function (e) {	
    
    		if ($(this).is(':radio:checked')) {
    			$(this).parents('form').find('input.switcher:radio[name="' + $(this).attr('name') + '"]').not(this).change();
    		}
    		var $targets = $('.switcher-target-' + $(this).attr('id'));
    
    		var is_show = $(this).is(':checked'); if ($(this).is('.switcher-reversed')) is_show = ! is_show;
    		if (is_show) {
    			$targets.slideDown();
    		} else {
    			$targets.slideUp().find('.clear-on-switch').add($targets.filter('.clear-on-switch')).val('');
    		}
    	}).change();
    

    Specifically due to the selector being used:

    
    var $targets = $('.switcher-target-' + $(this).attr('id'));
    

    Which should be changed to something like this, to escape the selector used before passing it to jQuery:

    
    function escapeSelector( myClass ) {
    	return '.' + myClass.replace( /(\>|\<|\'|\"|:|\.|\[|\]|,|=|@|\\|\/)/g, "\\$1" );
    }
    
    var $targets = $( escapeSelector( 'switcher-target-' +  $( this ).attr( 'id' ) ) );
    

    The escapeSelector class I pulled from jQuery’s website, adding adding ' " < > \ /:
    https://learn.jquery.com/using-jquery-core/faq/how-do-i-select-an-element-by-an-id-that-has-characters-used-in-css-notation/

    I posted this on the Rapid Addon issues since I can not find a repo for this version of WP All Import on GitHub:
    https://github.com/soflyy/wp-all-import-rapid-addon/issues/30

    • This topic was modified 5 years, 5 months ago by tripflex.
    • This topic was modified 5 years, 5 months ago by tripflex.
Viewing 1 replies (of 1 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hi @tripflex

    Thank you for the report – I’ve notified our developer about this. We’ll follow up on the GitHub issue once he’s able to investigate it.

Viewing 1 replies (of 1 total)
  • The topic ‘Enum/Radio values with special characters cause JS errors’ is closed to new replies.