wp-shortcake / shortcake

Shortcake makes using WordPress shortcodes a piece of cake.
GNU General Public License v2.0
665 stars 143 forks source link

JS error for Select option with number value #805

Open grappler opened 5 years ago

grappler commented 5 years ago

When using these two configurations I get an JS error in the console: Uncaught TypeError: data.value.split is not a function

[
    'label'   => esc_html__( 'Zoom', 'static-map' ),
    'attr'    => 'zoom',
    'type'    => 'select',
    'options' => range( 1, 22 ),
],
[
    'label'   => esc_html__( 'Zoom', 'static-map' ),
    'attr'    => 'zoom',
    'type'    => 'select',
    'options' => array_combine( range( 0, 22 ), range( 0, 22 ) ),
],

The reason for this is that the data.value has a typeof number instead of string in these cases.

If I change the code to the following it works fine.

[
    'label'   => esc_html__( 'Zoom', 'static-map' ),
    'attr'    => 'zoom',
    'type'    => 'select',
    'options' => array_combine( range( 1, 22 ), range( 1, 22 ) ),
],

Related change https://github.com/wp-shortcake/shortcake/pull/745