Using Bootstrap, StimulusReflex and Discard in a Rails application, I'm trying to implement a confirm modal before the actual reflex action is called. As it is now, this does not work and bypasses the modal. Here is the html/erb code:
<div class="form-group row">
<div class="col-sm-2 pl-4 pr-0 mt-4">
<% if is_admin? && product.persisted? %>
<%= link_to('Archive', '#', class: 'btn btn-outline-danger hoverable-border',
data: { confirm: 'Are you sure?', reflex: 'click->Products#archive', id: product.id }) %>
and the reflex #archive method:
def archive
@product ||= Product.find(element.dataset.id)
@product.discard
morph '#products-content', render(partial: 'shared/products/admin/index', locals: { products: @product.omd_practice.products })
end
What would be the best way to implement this? Do I need to call a StimulusJS action that performs the confirm modal and then fires the reflex? I'm new to Stimulus overall so a bit hazy on this.
I just use the
confirm:complete->
and it works perfectly. No need for creating a StimulusJS controller.