When you register the setting in JS, you need to supply the current value saved in the DB as the value, not some default value. So instead of:
var setting = new api.Setting( 'mySetting', 'JS Default Value?' );
You would need to obtain the value via some means like the REST API and then use it when instantiating. You also need to provide the transport. So it would look like this:
var setting = new api.Setting( 'mySetting', someResponse.value, { transport: 'postMessage' } );
Here are some examples of doing this:
Related Posts:
- Is it Possible to Extend WP Customize JS Methods?
- Customizer JS API: Defining control settings
- Customizer JS API: Adding a “dropdown-pages” control
- WordPress customizer get control
- Get a default value of the Customizer setting using wp.customize API (JS)
- Customizer JS API: Defining active_callback for a section
- Show sections based on a control in WordPress Customizer using JS API
- How do I add a class to Customizer preview based on class of Customizer control? (Customizer Javascript API)
- Get a default customizeAction text for a section using Customizer JS API
- Youtube api – stop video
- TypeError: res.status is not a function
- WP Rest API – How to get featured image
- Customizer JS API
- wp.customize.bind ready event not fired
- Show only images and videos in a wp.media window
- WordPress Rest API
- Is it possible to enqueue the Youtube API script or does it have to be inline?
- Detecting WordPress Customizer Panel
- WP Customizer set a value via javascript (to create presets)
- wp_customize_support_script – do I need it?
- Customizer – instantiating settings and controls via javascript
- Headless WordPress: How to authenticate front end requests?
- Customizer: When to use customize_preview_init VS customize_controls_enqueue_scripts
- Is there a client side API for handling transients or options?
- How to overwrite JS variable with wp_localize _script?
- Theme Customiser not live previewing changes on pseudo elements
- Hide/show customizer controls based on other settings in Customizer
- the Customizer – proper way to instantiate an image upload control via javascript
- Preserve Javascript Through Customizer Preview Navigation
- How to check if customize previewer is refreshing?
- JavaScript in WordPress Customizer
- Accessing customizer values in javascript
- Running JS after theme customizer finished initialization
- customize_preview_init: listening for any changes from Customizer preview area
- How to disable inline css styles generated by Gutenberg editor?
- How to conditionally show/hide controls & sections in WordPress customizer?
- Multiple Conditional Controllers
- Using webpack to add customizer live preview functionality – wp.customize is not a function
- Adding and removing hidden buttons from WordPress Customizer Tinymce widget editor using javascript API
- How to add customizer control via javascript ( wp.customizer.control.add )
- Load page in customizer preview on panel click?
- I am trying to add current logged in user to my zoho chat
- This page can’t load Google Maps correctly [closed]
- Adding Code into Theme Customizer Header
- Custom JS text area in customizer is being formatted wrong in document
- customize-controls.js – extend api.previewer
- how to use nimble-API and Display data?
- create timestamp links to jump to specific times on rumble videos
- Multiple jQuery inputs or binds in Customizer Control Javascripts
- WordPress Guternberg Content For React Native
- I would like to retrive JSON value and display it in wordpress page or widget
- LayersWP Customizer White Blank Screen
- Create new product with woocommerce REST API with javascript (clientside)?
- Receive “menu-toogle” event from section menu in customizer
- Anyway to disable the auto excerpt creation?
- What is TypeScript and why would I use it in place of JavaScript? [closed]
- How to do associative array/hashing in JavaScript
- How to play audio?
- How to write a countdown timer in JavaScript?
- TypeScript foreach return [duplicate]
- What does “javascript:void(0)” mean?
- What does this symbol mean in JavaScript?
- Go back button in a page
- ‘react-scripts’ is not recognized as an internal or external command
- Timers in React Native (this.setTimeout)
- CSS height 100% percent not working
- Angular 4 setting selected option in Dropdown
- How can I convert an image into Base64 string using JavaScript?
- What does ngf-select do and why is it needed for form validation?
- What is jQuery Unobtrusive Validation?
- Make Discord bot send picture with message with NodeJS
- RegEx for Javascript to allow only alphanumeric
- How to check for an undefined or null variable in JavaScript?
- HTML anchor link – href and onclick both?
- Can WordPress be made to support websockets?
- How to use wp.hooks.addAction() in React JS/Gutenberg?
- Remove extra Google Maps script
- single page wordpress
- initial open/toggle PluginDocumentSettingPanel panel in document setting block editor gutenberg
- How to wrap the content of the main tinyMCE editor with extra tags
- How do developers add “Smooth Transitions” to their sites?
- Exclude JS file from 404 error page
- How can I get my Calculate Contact Form 7 field to update with jQuery? [closed]
- Contact Form 7 – Uncaught TypeError: wpcf7.initForm is not a function [closed]
- Where is script-loader.php creating JS tags
- WP TinyMCE (Full + media ) – 4.8 JS Init Dynamicly
- Search for a keyword across post types in a Gutenberg component
- Calling a WordPress Custom JavaScript file
- WP Customizer compare and set a value via javascript
- print script on wordpress header after user registered
- How do I use this javascript correct with wordpress?
- How to display different content on the same page using different URLS
- Remove escape characters from JSON string pulled from a database
- Client side pre-save Javascript hook on all admin pages
- WP Gutenberg – custom block with two content fields
- How to identify which javascript is being executed
- How to keep close a sub-menu under homepage? [closed]
- How to implement custom URL handler to access JS modal content? [closed]
- Contact form 7 hide and show fields depending up on the condition [closed]
- wp_enqueue has a resource but doesn’t generate a script tag [duplicate]