-
Notifications
You must be signed in to change notification settings - Fork 571
Javascript API
Table of Contents generated with DocToc
- Document unhooking CMB2 event callbacks.
- Document using various CMB2 custom event callbacks.
- Document overriding (date/time/color) Picker options.
- Document log method.
- Document media modal override options.
CMB2 has several events that get triggered during various client-side interactions. Some events are triggered directly on the document
object, and some are triggered on specific elements. As with all jQuery event callbacks, the first parameter sent to the callback is the event object, but with the CMB2 events, other parameters are also provided, including the CMB2
object. Source: js/cmb2.js
Triggered before CMB2 starts setting up its functionality, on the document ready event.
Triggered when CMB2 finishes setting up its functionality, on the document ready event. If you want to add functionality related to CMB2's other events, this is the best event to hook into to ensure CMB2 is setup/ready.
Triggered when the metabox is expanded/collopsed, and borrows the event name from the core WordPress metabox Javascript. The .postbox
element that was toggled is passed to the callback as the 2nd parameter.
Triggered when a WordPress media modal instance is created to handle the various CMB2 media file types. Is also passed the CMB2.media
object (as well as the default CMB2
object).
Triggered when a selection is made inside the CMB2 media modal instance. Is also passed the current selection object, and the CMB2.media
object (as well as the default CMB2
object).
Triggered when a CMB2 media modal instance is opened. Is also passed the current selection object, and the CMB2.media
object (as well as the default CMB2
object).
Triggered when the 'Add group row' button is clicked, before CMB2 performs its actions. Is triggered on the 'add group row' buton (.cmb-add-group-row
), as well as passed that button element.
Triggered when the 'Add row'/'Add group row' buttons are clicked. Is triggered on the CMB2 Group element (.cmb-repeatable-group
). The callback event will have a group
property to determine if event was triggered on the 'Add row' or the 'Add group row' button. Also passed the new row jQuery element object.
Triggered when the 'Remove group row' button is clicked, before CMB2 performs its actions. Is triggered on the CMB2 Group element (.cmb-repeatable-group
), and is passed the 'remove group row' button.
Triggered when the 'Remove row'/'Remove group row' buttons are clicked. Is triggered on the CMB2 Group element (.cmb-repeatable-group
). The callback event will have a group
property to determine if event was triggered on the 'Remove row' or the 'Remove group row' button.
Triggered when the 'move up'/'move down' buttons are clicked, before CMB2 performs its actions (before shift occurs). Is triggered on the button element (.cmb-shift-rows'
). The callback event will be passed the jQuery button element, the jQuery "from" element (the element to be moved), and the jQuery "to" element (the element to be replaced/moved).
Triggered when the 'move up'/'move down' buttons are clicked, before CMB2 performs its actions (before the shift, but confirmed shift should occur). Is triggered on the button element (.cmb-shift-rows'
). The callback event will be passed the jQuery button element, the jQuery "from" element (the element to be moved), and the jQuery "to" element (the element to be replaced/moved).
Triggered when the 'move up'/'move down' buttons are clicked, after CMB2 performs its actions (shift is complete). Is triggered on the button element (.cmb-shift-rows'
). The callback event will be passed the jQuery button element, the jQuery "from" element (the element to be moved), and the jQuery "to" element (the element to be replaced/moved).
Documentation:
-
Installation
Installation instructions for various environments -
Basic Usage
Get up and running -
Advanced Usage
Not for the faint of heart -
Field Types
Breakdown of field types -
Examples
Examples for registering fields -
Field Parameters
Breakdown of common field parameters -
Display Options
Limit display of boxes -
Box Properties
Breakdown of box properties -
Troubleshooting
Common issues & how to deal with them -
Notable Changes in CMB2 (from original CMB)
CMB2 — a complete re-write -
Tips & Tricks
10x your CMB2 skills -
REST API
CMB2 data through WordPress REST API -
Javascript API
Work with CMB2 JS events & hooks
Advanced tutorials:
- Adding your own field types
- Adding your own show_on filters
- Displaying boxes on the front-end
- Using CMB to create an Admin Theme Options Page
- Create New Posts (or Custom Post Type) Entries Using A Front End Form
- Disable CMB2 Styles on Front End Forms
External Resources: