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

Merge branch 'issue-15068' into production.panel.sutty.nl

This commit is contained in:
f 2024-10-23 16:19:09 -03:00
commit 5906cc8285
No known key found for this signature in database

View file

@ -2,8 +2,7 @@ import { Controller } from "@hotwired/stimulus";
export default class extends Controller {
connect() {
this.originalFormData = new FormData(this.element);
this.originalFormDataSerialized = this.serializeFormData(this.originalFormData);
this.originalFormDataSerialized = this.serializeFormData(this.element);
this.submitting = false;
}
@ -33,13 +32,24 @@ export default class extends Controller {
event.preventDefault();
}
serializeFormData(formData) {
formData(form) {
const formData = new FormData(form);
formData.delete("authenticity_token");
return (new URLSearchParams(formData)).toString();;
return formData;
}
/*
* Elimina saltos de línea y espacios al serializar, para evitar
* detectar cambios cuando cambió el espaciado, por ejemplo cuando el
* editor con formato aplica espacios o elimina saltos de línea.
*/
serializeFormData(form) {
return (new URLSearchParams(this.formData(form))).toString().replaceAll("+", "").replaceAll("%0A", "");
}
hasChanged() {
return (this.originalFormDataSerialized !== this.serializeFormData(new FormData(this.element)));
return (this.originalFormDataSerialized !== this.serializeFormData(this.element));
}
}