Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Granite:id to granite:class

Avatar

Avatar
Validate 10
Level 2
Shaheena_Sheikh
Level 2

Like

1 like

Total Posts

87 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Give Back
Boost 1
Applaud 5
View profile

Avatar
Validate 10
Level 2
Shaheena_Sheikh
Level 2

Like

1 like

Total Posts

87 posts

Correct Reply

0 solutions
Top badges earned
Validate 10
Validate 1
Give Back
Boost 1
Applaud 5
View profile
Shaheena_Sheikh
Level 2

14-04-2021

If I replace:

 

const setOptions = function () {

let fontField = $(".cq-dialog").find("#fontField ")[0];
let optionItems = fontField.items;
optionItems.clear();
for (var i = 0; i < 1; i++) {
let obj = new Object();
let cnt = new Object();
obj["value"] = "#ffffff";
cnt["textContent"] = "white";
obj["content"] = cnt;
optionItems.add(obj);
}

};

with:

const setOptions = function () {
$(".coral3-Multifield-item").each(function( index ) {
let fontField = $(this).find(".fontField ");
var arah=["#ffffff","#000000",""];
var aran=["White","Black","No Color"];
fontField.prop('readOnly', false);
let optionItems=fontField.items;
optionItems.clear();
for (var i = 0; i < arah.length; i++) {
let obj = new Object();
let cnt = new Object();
obj["value"] = arah[i];
cnt["textContent"] = aran[i];
obj["content"] = cnt;
optionItems.add(obj);
}
})
};

In first case: I am using fontField as granite:id and in the second case I'm using granite:class. In first case, the color option items get added to the swatch and I am able to see the colors. But, in the second case the same code (using granite:class) stops working. I don't see any color in the swatch and optionItems shows as undefined.

In the first code i don't have a multifield, while in second code, my colorfield is within a multifield. The swatch is showing empty for the 2nd code because items are not getting added.

Screenshot (191).png

Console error: Cannot read property 'clear' of undefined for the line where optionItems are getting cleared.

Why does changing granite:id to class affect it?

 

@Anudeep_Garnepudi 

View Entire Topic

Avatar

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

404 likes

Total Posts

502 posts

Correct Reply

137 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile

Avatar
Affirm 100
Level 10
asutosh_jena
Level 10

Likes

404 likes

Total Posts

502 posts

Correct Reply

137 solutions
Top badges earned
Affirm 100
Ignite 1
Establish
Give Back 50
Give Back 5
View profile
asutosh_jena
Level 10

14-04-2021

Hi @Shaheena_Sheikh 

 

Please try with below:

let fontField = $(".cq-dialog").find(".font-field")[0];

$(this) refers to the parent element which is multifieldItem in this case.

 

Thanks!