Hello there,
I use a customized PageContent widget. My ambition is to fill the title field by choosing a page in the dropdown. For this a have a little js function called dynamicTitleHandler():
;(function($) {
$(document).ready(function() {
dynamicTitleHandler();
});
function dynamicTitleHandler() {
// Add widget click handler for dynamic title set
if ($('#usedWidgets-Sidebar').length) {
$('#usedWidgets-Sidebar .PageContentWidget select:first-child option').click(function() {
var title = $(this).text();
$(this).closest('.widgetFields').find('.field.text input').val(title);
});
}
}
})(jQuery);
I call it via Requirements::javascript(PAGECONTENT_DIR.'/javascript/pagecontent.js'); in getCMSFields().
It works fine, but only for the existing widgets. If I add a new one I have to call the function, but I don't know how. First I thought about adding a LiteralField to the widget form which calls it by onload.
new LiteralField('JSLoader', "<div onload='dynamicTitleHandler()'></div>")
but it isn't shown?
Any ideas, how to get it?