WordPress.org

Ready to get started?Download WordPress

Forums

Bug inside media-views.js? (3 posts)

  1. NumberKruncher
    Member
    Posted 1 year ago #

    I have created a hook which adds two controls to the "Edit Gallery" page (a "select" and a "checkbox"). The "select" control is working absolutely fine, but the checkbox is not working at all.

    It seems that the culprit is on line #3939 of media-views.js:

    } else if ( $setting.is('input[type="checkbox"]') ) {
        $setting.attr( 'checked', !! value );
    }

    When the checkbox is selected value is "true" (string type). When the checkbox is not selected, value is "false" (string type). The double-bang does not work in the case of string encoded boolean values:

    var stringTrue = 'true';
    var stringFalse = 'false';
    var boolTrue = true;
    var boolFalse = false;
    
    !!stringTrue // true
    !!stringFalse // true (correct, but wrong!!)
    !!boolTrue // true
    !!boolFalse // false

    This seems like a bug to me, am I right?

    Cheers!

  2. NumberKruncher
    Member
    Posted 1 year ago #

    Yep, the following change fixes this:

    } else if ( $setting.is('input[type="checkbox"]') ) {
        value = value !== false && value !== 'false';
        $setting.attr( 'checked', value );
    }
  3. NumberKruncher
    Member
    Posted 1 year ago #

    I have submitted a bug report here:
    http://core.trac.wordpress.org/ticket/23954

Topic Closed

This topic has been closed to new replies.

About this Topic