• Resolved codasys

    (@codasys)


    Hi,

    I try to create an event listener for the described event uni_cpo_set_price_event.
    Is there an example how to use them?

    I added the the following code:

    document.addEventListener(“uni_cpo_set_price_event”, function(e) {
    console.log(e.detail); // Prints “Example of an event”
    console.log(“You knocked?”);
    });

    But I get no output in the console (Firefox/Chrome).

    Are the events on by default or to I need to activate them?

    PS Maybe it will be good to extend the documentation with examples of how to use them.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author moomooagency

    (@moomooagency)

    Hi,

    This event is attached to the body and created in jQuery (we use this dependency in the version 4). Therefore, you have to use jQuery as well and subscribe to events like this:

    jQuery(document.body).on(‘uni_cpo_set_price_event’, function(){
    // your code
    });

    Plugin Author moomooagency

    (@moomooagency)

    BTW, yes, it has one argument, it is a price.

    • This reply was modified 4 years, 10 months ago by moomooagency.

    @codasys do you have the event working?
    So yes, i am very curious about your snippet!!

    • This reply was modified 4 years, 10 months ago by donbloothoofd.
    Thread Starter codasys

    (@codasys)

    Hi donbloothoofd,

    I’m not pretty sure what so curious about my snippet, but YES it works.
    The solution was written down by moomooagency (except that his code uses backtick instead of single qoute/double quotes)

    jQuery(document.body).on(“uni_cpo_set_price_event”, function(e)
    {
    // List of parameters
    console.log(“DEBUG: uni_cpo_set_price_event triggered, get values”);
    const width = Number(jQuery(“#uni_cpo_myvalue-field”).val());
    …..
    // or do something with e
    })

    Regards

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘JS Events’ is closed to new replies.