wlminimal

wlminimal

How to customize popup window from data: [confirm: Are you sure]?

Hi guys!

I have delete button something like this..
ve delete button something like this..

<%= button to: recipient_path(@conn, :delete, recipient.id), method: "delete",  data: [confirm: Are you sure],  class: "btn btn-danger delete-each-button" do %>
 <i class="material-icons icon-button">close</i>Delete
<% end %> 

and as you all know, it shows me a pop up window for confirm. but it is not pretty.
So I want to customize it with sweetalert2 javascript library.
But I don’t know how i can cancel the event and re-trigger the event.

I was doing something like this..

 var buttons = document.querySelectorAll('.delete-each-button');
  if(buttons.length !== 0) {
    buttons.forEach(function(button) {
      button.addEventListener('click', function(e){
        e.preventDefault();
         // sweetalert2 code..
        window.swal({
          title: 'Are you sure?',
          text:  'Remove contacts from Recipients List.',
          showCancelButton: true,
          confirmButtonColor: '#f44336',
          cancelButtonColor:  '#333333',
          confirmButtonText: 'Yes, Delete it!'
        }).then((result) => {
          if(result.value) {
            $(this).trigger('click');
          }
        })
      })
    })
  }

this code didn’t prevent default delete action with e.preventDefault();
How can I do this?

Most Liked

LostKobrakai

LostKobrakai

To change the behaviour of phoenix.js you need to run the latest version (2.12.) of phoenix_html: https://hexdocs.pm/phoenix_html/Phoenix.HTML.Link.html#link/2-overriding-the-default-confirm-behaviour

Where Next?

Popular in Questions Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
chokchit
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement