Check if new item is added to the multifield | Community
Skip to main content
Level 6
Apr 14, 2021 1:53 PM UTC
Solved

Check if new item is added to the multifield

I want to call a JS function when a new item is added to the multifield. I have tried: 

$(".cq-dialog").find("coral3-Button coral3-Button--secondary").on("click", funcName);

doesn't call my function.

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
New Participant
Apr 14, 2021 4:44 PM UTC

@shaheena_sheikh 

try the below code

$(document).on("dialog-ready", function(){ $("coral-multifield").children("button[coral-multifield-add]").on("click", function() { //Logic }); });

 

9 replies

Anudeep_Garnepudi
Anudeep_GarnepudiAccepted solution
New Participant
Apr 14, 2021 4:44 PM UTC

@shaheena_sheikh 

try the below code

$(document).on("dialog-ready", function(){ $("coral-multifield").children("button[coral-multifield-add]").on("click", function() { //Logic }); });

 

Translate
Level 6
Apr 15, 2021 5:53 AM UTC
thanks, it works!
Translate
Asutosh_Jena_
New Participant
Apr 14, 2021 3:01 PM UTC

Hi @shaheena_sheikh 

 

Please try the below code and it will work.

(function (document, $, ns) {
"use strict";

$(document).on("click", ".coral3-Button--secondary", function (e) {
e.stopPropagation();
e.preventDefault();
alert("Hi");
});

})(document, Granite.$, Granite.author);

 

 

Translate
Level 6
Apr 15, 2021 8:07 AM UTC
this works but has a problem. The alert gets kicked even if i click on a dropdown, colorfield swatch (these are also within multifield items) etc. that should only get triggered for the click event of Add button
Translate
Level 6
Apr 14, 2021 2:02 PM UTC

my func is getting triggered when i am opening the dialog. Not when i click on the Add button

Translate