Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

More than two <options>s are selected #26

Closed
scribu opened this Issue · 1 comment

1 participant

@scribu
Owner

Minimal code to reproduce:

echo scbForms::input( array(
    'name' => 'whatever',
    'type' => 'select',
    'choices' => array(
        '1/2',
        '1',
        '1 1/3',
    ),
    'selected' => '1 1/3'
) );

Result:

<label><select name="whatever">
<option value="1/2">1/2</option>
<option value="1" selected="selected">1</option>
<option value="1 1/3" selected="selected">1 1/3</option>
</select></label>

A user reported this bug against P2P:

http://wordpress.org/support/topic/issue-with-selects-on-the-post-editor

@scribu
Owner

Somehow, '1' gets casted to an integer, and in PHP, 1 == '1 1/3' is true, because why not?

@scribu scribu referenced this issue from a commit in scribu/wp-scb-framework-example
@scribu make testSelect() more accurate 8a775f1
@scribu scribu closed this issue from a commit
@scribu cast choices and selected values to strings before comparing
this is better than using === because it correctly handles edge cases where
either choices or values are cast to numbers

fixes #26
5113202
@scribu scribu closed this in 5113202
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.