5

I would like to get the Component Metadata fields with a fieldBuilder.

I am successfully using the 'Plan B' code snippet in this post to access Component Fields. However, I cannot intuitively see a method in the APi to get the Metadata fields in the same manner. Is this possible?

2 Answers 2

3

The fieldBuilder you are accessing from that post is for the SchemaBasedFields. I'm not sure if this is the official way of accessing the metadata fieldBuilder, but this is what I came up with playing around with it so far.

var tabs = $display.getView().properties.controls.TabControl,
    cardCount = tabs.properties.cards.length,
    fieldBuilder,
    card;

while (cardCount--) {
    card = tabs.properties.cards[cardCount];
    if (card.getId() === "MetadataTab") {
        fieldBuilder = card.properties.controls.fieldBuilder;
    }
}

Now you have a fieldBuilder that represents your metadata fields, and would do the same as you would for the normal fields to grab the control.

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

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

Hope that helps!

1
  • Thanks Alex for the help. Works perfectly. Also updated the blog post with your code, yabolka.com/…
    – robrtc
    Commented Jun 25, 2013 at 8:38
1

Hope that this helps you to access some metadata field from your component with a fieldBuilder:

$display.getView().getMetadataTab().properties.controls.fieldBuilder.getField("field_name");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.