Shortcode_Button icon indicating copy to clipboard operation
Shortcode_Button copied to clipboard

Multicheck Inline Causes Error When Passing in An Array as data.value

Open davidshq opened this issue 6 years ago • 0 comments

I have a CMB2 field that looks like:

	$fields[] = array(
		'name'    => __( 'Resource Type', 'gc-sermons' ),
		'desc'    => __( 'Select the type of resource to display.', 'gc-sermons' ),
		'id'      => 'resource_type',
		'type'    => 'multicheck_inline',
		'default' => $this->atts_defaults['resource_type'],
		'options' => array(
			'files' => __( 'Files', 'gc-sermons' ),
			'urls'  => __( 'URLs', 'gc-sermons' ),
		),
	);

The array is passed eventually to shortcode-quicktag-button.js and looks like: [ "files", "urls" ]. It is processed through btn._populateFields and because the data.type is multicheck_inline it is handed to the appropriate multicheck_inline switch case.

Where the first attempt to process it is run by:

data.value = data.value.replace( /\|~/g, '[' ).replace( /~\|/g, ']' ).replace( /\'/g, '"' );

Which throws an error:

shortcode-quicktag-button.js?ver=1.0.5:473 Uncaught TypeError: data.value.replace is not a function
    at HTMLBodyElement.btns._populateFields (shortcode-quicktag-button.js?ver=1.0.5:473)
    at HTMLBodyElement.dispatch (jquery.js?ver=1.12.4-wp:3)
    at HTMLBodyElement.r.handle (jquery.js?ver=1.12.4-wp:3)
    at Object.trigger (jquery.js?ver=1.12.4-wp:3)
    at Object.jQuery.event.trigger (jquery-migrate.js?ver=1.4.1:633)
    at HTMLInputElement.<anonymous> (jquery.js?ver=1.12.4-wp:3)
    at Function.each (jquery.js?ver=1.12.4-wp:2)
    at jQuery.fn.init.each (jquery.js?ver=1.12.4-wp:2)
    at jQuery.fn.init.trigger (jquery.js?ver=1.12.4-wp:3)
    at Array.<anonymous> (shortcode-quicktag-button.js?ver=1.0.5:273)

Which I think is because .replace is an operation executed on strings and not arrays.

Not sure if this is user error, going to keep looking into, but any help is appreciated!

davidshq avatar Feb 01 '20 23:02 davidshq