I am writing a simple plugin. In the code below, insertBefore runs 2 times and creates 2 elements. I couldn’t find a solution. I will be glad if you can help me how to fix it.
Thank you.
var things = new PgComponentType(‘krft.things’, ‘THINGS’);
things.selector = function ($el) {
return true
};
things.display_name = ‘tag’;
things.not_main_type = true;
things.sections = {
‘krft.things’: {
name: ‘THINGS’,
fields: {
‘krft.things.checkbox’: {
type: ‘checkbox’,
name: ‘Convert to Shortcode’,
action: ‘custom’,
value: ‘1’,
set_value: function (pgel, value) {
var strBefore1 = ‘``’;
var xcode = pgCreate(strBefore1);
console.warn(xcode);
xcode.insertBefore(pgel);
return value;
}
}
}
}
};
framework.addComponentType(things);