Okay so I have been trying to educate myself to create new panels sections and controls dynamically using customizer's JS API.
It has been frustrating few days and I was unable to get the exact way to achieve this via JS API.
So far, this is some thing I am doing to make it happen but with no success:
// for Settings
api.create(
params.id,
params.id,
params.default,
params.args
);
// for controls
var controlConstructor = api.controlConstructor[params.type];
var control = new controlConstructor(params.id, {
params: params,
previewer: api.previewer
});
api.control.add(
params.id,
control
);
//for Sections
var section = new api.Section(params.id, {
params: params
});
api.section.add( params.id, section );
api.section('section_id').activate();
None of them seem to work as the section doesn't appear and I have to run api.section('section_id').activate()
twice in console to make the section appear, the same is with control.