Hi,
The question is related to a new --convertFields feature. I have created a module called “buttons” with fields.mjs file which exports this function:
function buttons(maxLimit = 3, id ="buttons", controlling_field_path = "buttons.button_icon") {
const button = {
"id" : id,
"name" : id,
"display_width" : null,
"label" : id,
"required" : false,
"locked" : false,
"occurrence" : {
"min" : null,
"max" : maxLimit,
"sorting_label_field" : `${id}.button_text`,
"default" : 1
},
"children" : [ {
"id" : `${id}.button_text`,
"name" : "button_text",
"display_width" : null,
"label" : "Button Text",
"required" : false,
"locked" : false,
"validation_regex" : "",
"allow_new_line" : false,
"show_emoji_picker" : false,
"type" : "text",
"default" : "Button example"
}, {
"id" : `${id}.button_link`,
"name" : "button_link",
"display_width" : null,
"label" : "Button Link",
"required" : false,
"locked" : false,
"supported_types" : [ "EXTERNAL", "CONTENT", "FILE", "EMAIL_ADDRESS", "BLOG" ],
"show_advanced_rel_options" : false,
"type" : "link",
"default" : {
"url" : {
"content_id" : null,
"type" : "CONTENT",
"href" : ""
},
"open_in_new_tab" : false,
"no_follow" : false
}
}, {
"id" : "button_style",
"name" : "button_style",
"display_width" : null,
"label" : "Button Style",
"required" : false,
"locked" : false,
"display" : "select",
"choices" : [ [ "button--primary", "Primary" ], [ "button--secondary", "Secondary" ], [ "button__link", "Text button" ] ],
"multiple" : false,
"reordering_enabled" : true,
"preset" : null,
"type" : "choice",
"default" : "button--primary"
}, {
"id" : "button_icon",
"name" : "button_icon",
"display_width" : null,
"label" : "Button icon",
"required" : false,
"locked" : false,
"display" : "checkbox",
"type" : "boolean",
"default" : false
}, {
"id" : "icon_type",
"name" : "icon_type",
"display_width" : null,
"label" : "Icon type",
"required" : false,
"locked" : false,
"visibility" : {
"controlling_field" : null,
"controlling_field_path" : controlling_field_path,
"controlling_value_regex" : "true",
"property" : null,
"operator" : "EQUAL",
"access" : null
},
"display" : "select",
"choices" : [ [ "arrow", "Arrow" ], [ "check", "Check mark" ] ],
"multiple" : false,
"reordering_enabled" : true,
"preset" : null,
"type" : "choice",
"default" : "arrow"
} ],
"tab" : "CONTENT",
"expanded" : false,
"type" : "group",
"default" : [ {
"button_text" : "Button example",
"button_link" : {
"url" : {
"content_id" : null,
"type" : "CONTENT",
"href" : ""
},
"open_in_new_tab" : false,
"no_follow" : false
},
"button_style" : "button--primary",
"button_icon" : false,
"icon_type" : "arrow"
} ]
}
return [ button ]
}
export default buttons;
I want to inject these buttons fields into another module in two different group fields like so:
import button from '../elements/button.module/fields.mjs'
import heading from '../elements/heading.module/fields.mjs'
function contentCards() {
const leftButton = button("2", "buttons2", "left_card.buttons2.button_icon")[0]
const rightButton = button("2", "buttons2", "right_card.buttons2.button_icon")[0]
const leftCard = {
"id" : "27bdf84b-1d52-1540-a9e1-eaaea502892a",
"name" : "left_card",
"display_width" : null,
"label" : "Left card",
"required" : false,
"locked" : false,
"children" : [ {
"id" : "8b1b1c7d-fd3c-eb98-8e63-a2705d4055b4",
"name" : "title_1",
"display_width" : null,
"label" : "Title-1",
"required" : false,
"locked" : false,
"validation_regex" : "",
"allow_new_line" : false,
"show_emoji_picker" : false,
"type" : "text",
"default" : "Apex title"
},
{
"id" : "bef61feb-53e1-41fd-7175-c0ecd6362530",
"name" : "paragraph_1",
"display_width" : null,
"label" : "Paragraph-1",
"required" : false,
"locked" : false,
"validation_regex" : "",
"allow_new_line" : false,
"show_emoji_picker" : false,
"type" : "text",
"default" : "Lacinia nam sed purus tempor id nunc vulputate. Sapien lorem integer eget quis suspendisse nulla. Ultricies scelerisque et pulvinar **bleep** at mauris."
}, {
"id" : "2630f0c6-9cc2-a5df-e8e0-6c8781bba212",
"name" : "image_1",
"display_width" : null,
"label" : "Image-1",
"required" : false,
"locked" : false,
"responsive" : true,
"resizable" : true,
"show_loading" : false,
"type" : "image",
"default" : {
"size_type" : "auto",
"src" : "https://26812157.fs1.hubspotusercontent-eu1.net/hubfs/26812157/test-folder/Apex_brand_lhd_RGB%201.png",
"alt" : "Apex_brand_lhd_RGB 1",
"loading" : "lazy",
"width" : 933,
"height" : 829,
"max_width" : 933,
"max_height" : 829
}
}, leftButton ],
"tab" : "CONTENT",
"expanded" : false,
"type" : "group",
"default" : {
"title_1" : "Apex title",
"paragraph_1" : "Lacinia nam sed purus tempor id nunc vulputate. Sapien lorem integer eget quis suspendisse nulla. Ultricies scelerisque et pulvinar **bleep** at mauris.",
"image_1" : {
"size_type" : "auto",
"src" : "https://26812157.fs1.hubspotusercontent-eu1.net/hubfs/26812157/test-folder/Apex_brand_lhd_RGB%201.png",
"alt" : "Apex_brand_lhd_RGB 1",
"loading" : "lazy",
"width" : 933,
"height" : 829,
"max_width" : 933,
"max_height" : 829
}
}
}
const rightCard = {
"id" : "17c0ef67-6aa8-6fe0-3df9-00f8033d1f96",
"name" : "right_card",
"display_width" : null,
"label" : "Right card",
"required" : false,
"locked" : false,
"children" : [ {
"id" : "791e25f4-3152-925c-94d6-d3dec3372f51",
"name" : "title_2",
"display_width" : null,
"label" : "Title-2",
"required" : false,
"locked" : false,
"validation_regex" : "",
"allow_new_line" : false,
"show_emoji_picker" : false,
"type" : "text",
"default" : "Apex title"
}, {
"id" : "fdc55d4e-2a5c-9a16-acb9-5176f5e7794f",
"name" : "paragraph_2",
"display_width" : null,
"label" : "Paragraph-2",
"required" : false,
"locked" : true,
"validation_regex" : "",
"allow_new_line" : false,
"show_emoji_picker" : false,
"type" : "text",
"default" : "Lacinia nam sed purus tempor id nunc vulputate. Sapien lorem integer eget quis suspendisse nulla. Ultricies scelerisque et pulvinar **bleep** at mauris."
}, {
"id" : "e581424a-83c2-5cb1-362f-e8ba75603ff1",
"name" : "image_2",
"display_width" : null,
"label" : "Image-2",
"required" : false,
"locked" : false,
"responsive" : true,
"resizable" : true,
"show_loading" : false,
"type" : "image",
"default" : {
"size_type" : "auto",
"src" : "https://26812157.fs1.hubspotusercontent-eu1.net/hubfs/26812157/test-folder/Apex_brand_lhd_RGB%201.png",
"alt" : "Apex_brand_lhd_RGB 1",
"loading" : "lazy",
"width" : 933,
"height" : 829,
"max_width" : 933,
"max_height" : 829
}
}, rightButton ],
"tab" : "CONTENT",
"expanded" : false,
"type" : "group",
"default" : {
"title_2" : "Apex title",
"paragraph_2" : "Lacinia nam sed purus tempor id nunc vulputate. Sapien lorem integer eget quis suspendisse nulla. Ultricies scelerisque et pulvinar **bleep** at mauris.",
"image_2" : {
"size_type" : "auto",
"src" : "https://26812157.fs1.hubspotusercontent-eu1.net/hubfs/26812157/test-folder/Apex_brand_lhd_RGB%201.png",
"alt" : "Apex_brand_lhd_RGB 1",
"loading" : "lazy",
"width" : 933,
"height" : 829,
"max_width" : 933,
"max_height" : 829
}
}
}
return [ heading('h1'), leftCard, rightCard ]
}
export default contentCards;
For some reason it works only for one card. So if I add only leftButton to leftCard object, then it successfully uploads the fields and everything works, but it doesn’t work if I add both buttons to two cards at the same time.
What am I doing wrong? I’m changing the id’s and controlling_field_path as they might be conflicting, but it always throws this error - [ERROR] Unrecognized token ‘import’: was expecting (JSON String, Number, Array, Object or token ‘null’, ‘true’ or ‘false’) (line:1, column:8)
Would appreciate any help.