Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroy link not working throws Uncaught (in promise) TypeError: link.getAttribute is not a function Error #8

Open
rahulwadi opened this issue Sep 26, 2017 · 2 comments

Comments

@rahulwadi
Copy link

After selecting okay on sweet alert, I get following error in js console and request doesn't reach rails server.

Uncaught (in promise) TypeError: link.getAttribute is not a function
  at Object.Rails.handleMethod (rails-ujs.self-....js:471)
    at sweetAlertConfirmedCallback (sweet-alert2-rails.self-...js:37)
    at <anonymous>

link_to code for reference:

<%= link_to 'Delete', object_path(object), method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger' %>
@spimentel3
Copy link

spimentel3 commented Aug 10, 2018

Just hit the same issue. Did you ever figure out a solution? I'm going to keep digging for a fix or make a pr if I can fix it.

@spimentel3
Copy link

spimentel3 commented Aug 10, 2018

So what I ended up doing to fix it was wrapping it in a form.

Going from

<%= link_to "Delete Project", @project, method: :delete, data: { confirm: 'Are you sure?',
                                                                               'confirm-button-text': 'Do it!',
                                                                               'cancel-button-text': 'Nah, not yet',
                                                                               'confirm-button-color': '#3a96d1',
                                                                               'sweet-alert-type': 'error',
                                                                               text: 'You won\'t'}, class: "btn red" %>

to

<%= form_for @project, method: :delete do |f| %>
              <%= f.submit "Delete Project", class: "btn red accent-4", data: { confirm: 'Are you sure?',
                                                                                'confirm-button-text': 'Do it!',
                                                                                'cancel-button-text': 'Nah, not yet',
                                                                                'confirm-button-color': '#3a96d1',
                                                                                'sweet-alert-type': 'error',
                                                                                text: 'You won\'t'} %>
            <% end %>

There is an issue in sweetAlertConfirmedCallback() trying to reference data that hasn't been properly set.

Rails.handleMethod = function(e) {
        var csrfParam, csrfToken, form, formContent, href, link, method;
        link = this;
        method = link.getAttribute('data-method');  // <----- This guy throws a fit.
        ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants