5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 06:56:23 +00:00

fix: no detectar espaciado como cambios #17649

This commit is contained in:
f 2024-10-23 16:18:12 -03:00
parent 52322c15c5
commit 2c5465fc0d
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 { export default class extends Controller {
connect() { connect() {
this.originalFormData = new FormData(this.element); this.originalFormDataSerialized = this.serializeFormData(this.element);
this.originalFormDataSerialized = this.serializeFormData(this.originalFormData);
this.submitting = false; this.submitting = false;
} }
@ -33,13 +32,24 @@ export default class extends Controller {
event.preventDefault(); event.preventDefault();
} }
serializeFormData(formData) { formData(form) {
const formData = new FormData(form);
formData.delete("authenticity_token"); 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() { hasChanged() {
return (this.originalFormDataSerialized !== this.serializeFormData(new FormData(this.element))); return (this.originalFormDataSerialized !== this.serializeFormData(this.element));
} }
} }