[wp-trac] [WordPress Trac] #23954: Checkbox value is not updated correctly inside media-views.js
WordPress Trac
noreply at wordpress.org
Fri Apr 5 23:09:51 UTC 2013
#23954: Checkbox value is not updated correctly inside media-views.js
----------------------------+------------------------------
Reporter: NumberKruncher | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: 3.5.1
Severity: major | Resolution:
Keywords: needs-patch |
----------------------------+------------------------------
Comment (by NumberKruncher):
> thanks for submitting that bug report - i could work on the patch, but
first can you provide the code that you are using to produce the problem,
the code that uses the hook; being able to reproduce the bug here will be
critical to testing whether your proposed fix works in my dev environment.
Here is a video that demonstrates the problem:
http://www.youtube.com/watch?v=LRkWqIEiRqk
This is the plugin used in the demonstration video:
{{{
<?php defined('WPINC') or die('Access denied.');
/*
Plugin Name: GalleryBugReport
*/
class GalleryBugReport {
function __construct() {
add_action('print_media_templates', array(&$this,
'on_print_media_templates'));
}
function on_print_media_templates() {
if (!isset(get_current_screen()->id) ||
get_current_screen()->base != 'post')
return;
$sizes = array(
'thumbnails' => 'Thumbnails',
'carousel' => 'Carousel',
'simple-list' => 'Simple List'
);
?>
<script type="text/javascript">
jQuery(function() {
var $ = jQuery;
var media = wp.media;
// Wrap the render() function to append controls
media.view.Settings.Gallery = media.view.Settings.Gallery.extend({
render: function() {
media.view.Settings.prototype.render.apply(this,
arguments);
// Append the custom template.
this.$el.append(media.template('custom-gallery-
settings'));
// Save the setting.
media.gallery.defaults.show_captions = true;
this.update.call(this, 'show_captions');
return this;
}
})
})
</script>
<script type="text/html" id="tmpl-custom-gallery-settings">
<label class="setting">
<span>Show Captions</span>
<input type="checkbox" data-setting="show_captions"/>
</label>
</script>
<?php
}
}
new GalleryBugReport();
?>
}}}
> i have a question about your code: why are you checking for both false
and 'false' can't we be sure it will be one or the other?
Sometimes the value comes through as boolean and sometimes the value comes
through as a string encoded representation of the boolean value. So the
code needs to cater for both approaches.
I assume that the double-bang was intended to prevent this very issue
(because I cannot think of any other reason to use a double-bang there).
--
Ticket URL: <http://core.trac.wordpress.org/ticket/23954#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list