WordPress.org

Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 5 years ago

#30701 closed defect (bug) (fixed)

Failures calling wp.customize.Control.activate() or wp.customize.Control.deactivate()

Reported by: westonruter Owned by: ocean90
Milestone: 4.1 Priority: normal
Severity: normal Version: 4.1
Component: Customize Keywords:
Focuses: javascript Cc:

Description

The wp.customize.Control class has two methods activate() and deactivate() which are ‘imported’ from wp.customize.Section and wp.customize.Panel. The activate and deactivate methods are just wrappers around the _toggleActive method. This method is defined on wp.customize.Section and wp.customize.Panel but it was not imported into wp.customize.Control as well, so when you attempt to call control.activate() or control.deactivate() you get the infamous Undefined is not a function since control._toggleActive does not exist.

To reproduce the issue, try running this from the console:

wp.customize.control('blogname').deactivate()

The fix is simple:

  • src/wp-admin/js/customize-controls.js

     
    913913                 */
    914914                deactivate: Container.prototype.deactivate,
    915915
     916                /**
     917                 * Re-use _toggleActive from Container class.
     918                 *
     919                 * @access private
     920                 */
     921                _toggleActive: Container.prototype._toggleActive,
     922
    916923                dropdownInit: function() {
    917924                        var control      = this,
    918925                                statuses     = this.container.find('.dropdown-status'),

For interim fix if this does not make it into 4.1 is for plugins to do this:

if ( ! wp.customize.Control.prototype._toggleActive ) {
    wp.customize.Control.prototype._toggleActive = wp.customize.Section.prototype._toggleActive;
}

Relates to the Customizer JS APIs added in #28709. Props to celloexpressions for alerting me to the issue.

Attachments (2)

30701.diff (544 bytes) - added by westonruter 6 years ago.
Import missing wp.customize.Control.prototype._toggleActive
30701.2.diff (19.6 KB) - added by westonruter 6 years ago.
https://github.com/xwp/wordpress-develop/pull/58

Download all attachments as: .zip

Change History (19)

@westonruter
6 years ago

Import missing wp.customize.Control.prototype._toggleActive

#1 @westonruter
6 years ago

  • Keywords has-patch commit added
  • Owner set to ocean90
  • Status changed from new to reviewing

#2 @ocean90
6 years ago

30701.diff makes sense.

#3 @westonruter
6 years ago

In 30701.2.diff I added a lot more unit tests to improve coverage on the new models, including these activate()/deactivate() methods.

#4 @ocean90
6 years ago

In 30871:

Customizer: Import missing wp.customize.Control.prototype._toggleActive.

Check also if completeCallback is set before calling it.

props westonruter.
see #30701.

#5 follow-up: @ocean90
6 years ago

  • Keywords fixed-major added

Let's move the unit tests to a new ticket for now.

#6 in reply to: ↑ 5 @westonruter
6 years ago

Replying to ocean90:

Let's move the unit tests to a new ticket for now.

Should not unit test patches be kept on the tickets for the issues they verify?

This ticket was mentioned in Slack in #core by johnbillion. View the logs.


6 years ago

#8 @johnbillion
6 years ago

In 30916:

Customizer: Import missing wp.customize.Control.prototype._toggleActive.

Check also if completeCallback is set before calling it.

Merges [30871] to the 4.1 branch.

Props westonruter.
See #30701.

#9 @ocean90
6 years ago

In 30919:

Customizer: Add more QUnit tests to improve coverage on the new models.

Includes tests for the broken activate()/deactivate() methods, which were fixed in [30871].

props westonruter.
see #30701.

#10 @nacin
6 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

#11 @jorbin
6 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

#12 follow-up: @westonruter
6 years ago

Strange. Travis reports the error:

Error: Syntax error, unrecognized expression: unsupported pseudo: focusable

But this is valid jQuery: http://api.jqueryui.com/focusable-selector/

This ticket was mentioned in Slack in #core by ocean90. View the logs.


6 years ago

#14 in reply to: ↑ 12 @ocean90
6 years ago

Replying to westonruter:

But this is valid jQuery: http://api.jqueryui.com/focusable-selector/

jQuery UI, which trunk/tests/qunit/index.html doesn't enqeue as a dependency yet. Can't really test this, works locally.

#15 @johnbillion
6 years ago

  • Keywords has-patch commit fixed-major removed
  • Resolution set to fixed
  • Status changed from reopened to closed

Closing this as fixed for 4.1 with [30871].

See #30754 for the qunit failure.

#16 @jorbin
6 years ago

In 30989:

Add jQuery UI Core as a dependency for qUnit tests

[30919] added more qUnit tests for the Customizer. One of the dependencies for these tests is qUnit. Otherwise we end up with an error due to an unsupported pseudo.

https://travis-ci.org/aaronjorbin/develop.wordpress/jobs/44873635#L425 shows an example of the failing test.

Props ocean90.
see #30701.
Fixes #30754.

#17 @iseulde
5 years ago

In 32701:

Customizer: hide controls on test page

Introduced in [30919].
See #32577 and #30701.

Note: See TracTickets for help on using tickets.