5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 21:06:22 +00:00

fix: volver a mostrar los mensajes al guardar y validar

This commit is contained in:
f 2024-06-19 14:28:53 -03:00
parent 084cf69f93
commit 654fff0ab9
No known key found for this signature in database
5 changed files with 38 additions and 12 deletions

View file

@ -1,6 +1,8 @@
import { Controller } from "stimulus"; import { Controller } from "stimulus";
export default class extends Controller { export default class extends Controller {
static targets = ["invalid", "submitting"];
connect() { connect() {
this.element.setAttribute("novalidate", true); this.element.setAttribute("novalidate", true);
@ -22,8 +24,29 @@ export default class extends Controller {
if (this.element.reportValidity()) { if (this.element.reportValidity()) {
this.element.classList.remove("was-validated"); this.element.classList.remove("was-validated");
this.element.submit(); this.element.submit();
this.show(this.submittingTargets);
this.hide(this.invalidTargets);
} else { } else {
this.element.classList.add("was-validated"); this.element.classList.add("was-validated");
this.hide(this.submittingTargets);
this.show(this.invalidTargets);
}
}
show(elements) {
for (const element of elements) {
element.classList.remove("d-none");
setTimeout(() => element.classList.add("show"), 1);
}
}
hide(elements) {
for (const element of elements) {
element.classList.remove("show");
setTimeout(() => element.classList.add("d-none"), 2000);
} }
} }
} }

View file

@ -1,2 +1,2 @@
.alert.alert-primary.mx-auto.content.max-w-md-70ch{ role: 'alert', class: local_assigns[:class] } .alert.alert-primary.mx-auto.content.max-w-md-70ch{ role: 'alert', **local_assigns }
= yield = yield

View file

@ -1,8 +1,11 @@
- invalid_help = site.config.fetch('invalid_help', t('.invalid_help')) - invalid_help = site.config.fetch('invalid_help', t('.invalid_help'))
- sending_help = site.config.fetch('sending_help', t('.sending_help')) - submitting_help = site.config.fetch('submitting_help', t('.submitting_help'))
.form-group
= submit_tag t('.save'), class: 'btn btn-secondary submit-post' .d-flex.flex-column.flex-md-row.align-items-start.mb-3
= render 'bootstrap/alert', class: 'invalid-help d-none' do %div
= invalid_help = submit_tag t('.save'), class: 'btn btn-secondary submit-post'
= render 'bootstrap/alert', class: 'sending-help d-none' do .d-flex.flex-column.position-relative
= sending_help = render 'bootstrap/alert', class: 'm-0 d-none fade', data: { target: 'form-validation.invalid' } do
= invalid_help
= render 'bootstrap/alert', class: 'm-0 d-none fade position-absolute top-0 left-0', data: { target: 'form-validation.submitting' } do
= submitting_help

View file

@ -719,8 +719,8 @@ en:
submit: submit:
save: 'Save' save: 'Save'
save_draft: 'Save as draft' save_draft: 'Save as draft'
invalid_help: 'Some fields need attention! Please search for the fields marked as invalid.' invalid_help: "Some fields need attention! Please search for the fields marked as not valid."
sending_help: Saving, please wait... submitting_help: "Saving changes, please wait..."
new_array: new_array:
remove: "Remove" remove: "Remove"
attributes: attributes:

View file

@ -727,8 +727,8 @@ es:
submit: submit:
save: 'Guardar' save: 'Guardar'
save_draft: 'Guardar como borrador' save_draft: 'Guardar como borrador'
invalid_help: '¡Te faltan completar algunos campos! Busca los que estén marcados como inválidos' invalid_help: "¡Te falta completar algunos campos! Busca los que estén marcados como no válidos."
sending_help: Guardando, por favor espera... submitting_help: "Guardando, por favor espera..."
new_array: new_array:
remove: "Eliminar" remove: "Eliminar"
attributes: attributes: