Skip to main content
Added plan B
Source Link
UI Beardcore
  • 2.3k
  • 12
  • 13

* * *

and plan "B", is to listen on on fieldbuilder "load" event

if ($display)
{
    (function()
    {
        $evt.addEventHandler($display, "start", Extension$onDisplayStartedReadonly);

        function Extension$onDisplayStartedReadonly()
        {
            $evt.removeEventHandler($display, "start", Extension$onDisplayStartedReadonly);

            var view = $display.getView();
            if (view && Tridion.OO.implementsInterface(view, "Tridion.Cme.Views.Component"))
            {
                var fieldBuilder = view.properties.controls.fieldBuilder;
                $evt.addEventHandler(fieldBuilder, "load", Extension$onDisplayStartedReadonly$_collectProperties);
            }
        };

        function Extension$onDisplayStartedReadonly$_collectProperties(event)
        {
            var fieldBuilder = event && event.source;
            if (fieldBuilder)
            {
                var fieldsContainer = fieldBuilder.properties.input;
                var fieldsNode = fieldsContainer.getElement();
                var control = null;

                $j(fieldsNode).children().each(function (index, elm)
                {
                    var cntrl = $j('div.input', elm)[0].control;
                    console.log('fieldname=' + cntrl.getFieldName());
                });
            }
        };
    })();
}

* * *

and plan "B", is to listen on on fieldbuilder "load" event

if ($display)
{
    (function()
    {
        $evt.addEventHandler($display, "start", Extension$onDisplayStartedReadonly);

        function Extension$onDisplayStartedReadonly()
        {
            $evt.removeEventHandler($display, "start", Extension$onDisplayStartedReadonly);

            var view = $display.getView();
            if (view && Tridion.OO.implementsInterface(view, "Tridion.Cme.Views.Component"))
            {
                var fieldBuilder = view.properties.controls.fieldBuilder;
                $evt.addEventHandler(fieldBuilder, "load", Extension$onDisplayStartedReadonly$_collectProperties);
            }
        };

        function Extension$onDisplayStartedReadonly$_collectProperties(event)
        {
            var fieldBuilder = event && event.source;
            if (fieldBuilder)
            {
                var fieldsContainer = fieldBuilder.properties.input;
                var fieldsNode = fieldsContainer.getElement();
                var control = null;

                $j(fieldsNode).children().each(function (index, elm)
                {
                    var cntrl = $j('div.input', elm)[0].control;
                    console.log('fieldname=' + cntrl.getFieldName());
                });
            }
        };
    })();
}
Source Link
UI Beardcore
  • 2.3k
  • 12
  • 13

You can run your extension code when the thread gets executed. To do so, try following

function onDisplayStartedReadonly() 
{
    $evt.removeEventHandler($display, "start", onDisplayStartedReadonly);

    function onDisplayStartedReadonly$_collectProperties()
    {
        if ($display.getView().getId() == "ComponentView") 
        {
            debugger;
            var fieldBuilder = $display.getView().properties.controls.fieldBuilder;

            fieldsContainer = fieldBuilder.properties.input;
            fieldsNode = fieldsContainer.getElement();
            control = null;

            $j(fieldsNode).children().each(function (index, elm) {
                var cntrl = $j('div.input', elm)[0].control;
                console.log('fieldname=' + cntrl.getFieldName());
            });
        }
    }
    
    setTimeout(onDisplayStartedReadonly$_collectProperties, 0);
}