Skip to content

Commit

Permalink
fix: button submitters now work (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonnorRogers authored Nov 23, 2021
1 parent f275d80 commit 917d362
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/elementDisabler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ function disableFormElement (element: HTMLFormElement): void {
}
}

element.disabled = true
element.dataset.ujsDisabled = 'true'

// Due to how FormSubmissions work in Chrome, if the button is disabled prior
// to submitting the form, then form "submit" event will never trigger.
setTimeout(() => { element.disabled = true })
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/method.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AJAX_EVENTS, dispatch, stopEverything } from './utils/events'
import { AJAX_EVENTS, dispatch } from './utils/events'
import { EventQueryInterface, MrujsPluginInterface } from '../types'
import { addListeners, removeListeners, attachObserverCallback } from './utils/dom'
import { MethodSubmission } from './methodSubmission'
Expand Down Expand Up @@ -57,7 +57,7 @@ export function handleMethod (event: Event): void {

if (href == null) return

stopEverything(event)
event.preventDefault()
const submitter = event.target

const linkSubmission = MethodSubmission(element)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const BASE_SELECTORS: QuerySelectorInterface = {
linkDisableSelector: `a[${disableWith}], a[${disable}]`,

// Button onClick disable selector with possible reenable after remote submission
buttonDisableSelector: `button[${disableWith}], button[${disable}]`,
buttonDisableSelector: `button[data-remote][${disableWith}], button[data-remote][${disable}]`,
fileInputSelector: 'fileInputSelector: \'input[name][type=file]:not([disabled])\''
}

Expand Down
8 changes: 6 additions & 2 deletions test/rails/dummy/app/javascript/packs/application.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mrujs from 'mrujs'
// import Racks from "@rails/ujs"
import Rails from 'mrujs'
import { ActiveStorage, JsErb } from "mrujs/plugins"
// import { JsErb } from "mrujs/plugins"
// import * as ActiveStorage from "@rails/activestorage"
Expand All @@ -14,12 +15,15 @@ import "../stylesheets/application.css"
}
})()

mrujs.start({
Rails.start({
plugins: [
JsErb(),
ActiveStorage()
]
})

// window.Racks = Racks
// Racks.start()
// ActiveStorage.start()

document.addEventListener("direct-upload:initialize", event => {
Expand Down
3 changes: 2 additions & 1 deletion test/rails/dummy/app/views/posts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<%= render partial: "posts/form_body", locals: {form: form, post: post} %>

<div class="actions">
<%= form.submit nil, data: {"disable-with" => "Submitting..."} %>
<%# <%= form.submit nil, data: {"disable-with" => "Submitting..."} %1> %>
<%= form.button nil, data: {"disable-with" => "Submitting..."} %>
</div>
<% end %>

Expand Down

0 comments on commit 917d362

Please sign in to comment.