mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-23 02:46:22 +00:00
Merge branch 'issue-15068' into production.panel.sutty.nl
This commit is contained in:
commit
5906cc8285
1 changed files with 15 additions and 5 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue