mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 10:56: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 {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue