Commit 2908d930 authored by f's avatar f
Browse files

informar el delay para enviar el formulario

parent fe682d22
......@@ -9,6 +9,8 @@ envío del formulario.
encuentra en _data/forms/contacto.yml
{% endcomment %}
<form
data-controller="contact"
data-delay="60"
action="https://api.sutty.nl/v1/sites/{{ site.hostname }}/contact/{{ include.name }}"
method="post">
{%- for field in include.form -%}
......
<input type="submit" class="btn btn-success" value="{{ include.field[1].label[site.locale] }}" />
<input
data-target="contact.submit"
type="submit"
class="btn btn-success"
value="{{ include.field[1].label[site.locale] }}" />
import { Controller } from 'stimulus'
/*
* Sólo permite enviar el formulario de contacto después de unos
* segundos, para evitar el spam.
*/
export default class extends Controller {
static targets = [ 'submit' ]
connect () {
if (!this.hasSubmitTarget) return
this.submitTarget.disabled = true
this._value = this.submitTarget.value
// Esperar un minuto desde que se carga la página hasta que se
// permite enviar.
this._interval = setInterval(() => {
const delay = this.delay
if (this.delay == 0) {
clearInterval(this._interval)
this.submitTarget.disabled = false
this.submitTarget.value = this._value
} else {
this.delay = delay - 1
}
}, 1000)
}
get delay () {
const delay = parseInt(this.element.dataset.delay)
return isNaN(delay) ? 0 : delay
}
set delay (value) {
this.element.dataset.delay = value
this.submitTarget.value = `${this._value} (${value})`
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment