0

I have several Fuel UX placards on a page, with a single jQuery selector to initialize them all. I need to write a custom onAccept function to handle placard confirmation.

It seems like I should be able to access $(this) from within the onAccept to access the element being initialized, but it just points to the window object.

How can I go about accessing the current element in a placard onAccept function?

Here's my code for reference:

$(".select-user-placard").placard({explicit: true, onAccept: function (helpers) {
    DMSC.UpdateUser(DMSC.SelectedForm.Id, $(this).data("field-type"), helpers.value);
}});

I need to call this function passing a parameter that is retrieved from a data-attribute on the element, but I'm not sure how I can access the current element without the use of this.

Tevis
  • 729
  • 1
  • 12
  • 27

1 Answers1

1

I guess I was kind of thrown by the no access to this and I couldn't think of the obvious solution:

            $(".select-user-placard").each(function (index, element) {
                var $element = $(element);

                $element.placard({explicit: true, onAccept: function (helpers) {
                    DMSC.UpdateUser(DMSC.SelectedForm.Id, $element.data("field-type"), helpers.value);
                }});
            });

Instead of calling placard on the jQuery selector, I iterate over each using jQuery's each and just use the jQuery iterator to select that element's data.

Tevis
  • 729
  • 1
  • 12
  • 27