bonny / WordPress-Simple-Fields

WordPress plugin that extend Custom Fields to include textareas, WYSIWYG-editor, files, attachments, well basically anything
http://wordpress.org/extend/plugins/simple-fields/
88 stars 23 forks source link

Last value of dropdown field duplicated #98

Open powerbuoy opened 10 years ago

powerbuoy commented 10 years ago

When adding a dropdown field using the PHP API the last value in the dropdown gets duplicated in the top.

With this code:

simple_fields_register_field_group('sections_group', array(
[...]
array(
    'slug'              => 'color', 
    'name'              => __('Color', 'h5b'), 
    'type'              => 'dropdown', 
    'options'           => array(
        'values'        => array(
            array(
                'num'   => 'red', 
                'value' => __('Red', 'h5b')
            ), 
            array(
                'num'   => 'green', 
                'value' => __('Green', 'h5b')
            ), 
            array(
                'num'   => 'blue', 
                'value' => __('Blue', 'h5b')
            )
        )
    )
)
[...]
));

The generated dropdown looks like this:

<select [...]>
    <option value="dropdown_num_0">Blue</option>
    <option value="dropdown_num_red">Red</option>
    <option value="dropdown_num_green">Green</option>
    <option value="dropdown_num_blue">Blue</option>
</select>

As you can see the value is 0 even though the text is the same as the last option's. Perhaps I'm missing something (like perhaps you can pass in the first option's text somewhere to the function) but even still it's kind of weird it duplicates the last one.

Also, I was a bit surprised all of my values were prepended with "dropdownnum" - is there any way to avoid this?

Cheers

bonny commented 10 years ago

I believe the "num" should be a number, so maybe that's what confusing the plugin. Try changing it to numbers and see if that helps.

The dropdopnum is required and the idea is that you can change the values of a dropdown and still all your php functions etc will still work because you reference them by number and not name.

powerbuoy commented 10 years ago

You are correct in that switching to numbers fixes the duplication problem (for some reason :P) but the weird thing is that nothing except the duplication issue prevents you from using text. I mean SimpleFields doesn't throw an error or output a faulty