mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 06:36:21 +00:00
fix: no detectar espaciado como cambios #17649
This commit is contained in:
parent
52322c15c5
commit
2c5465fc0d
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