fix: BlurInput was not updating the object in some situations

Steps to reproduce:
- click in any BlurInput
- change to any value
- click outside the input => the value will be set to the object
- click again in the input
- change value to the initial
- click outside => the value will not be set

This is because the BlurInput in sync on blur, and it was comparing
the current field value with an "initial" one, only set at build.
This check is made because we don't want to trigger an edit when a
user click in a blurinput and click outside without changing the value.
This commit is contained in:
Yohan Boniface 2024-07-09 10:46:22 +02:00
parent 45b9db4242
commit 3be274929a
3 changed files with 6 additions and 5 deletions

View file

@ -49,7 +49,7 @@
"leaflet-contextmenu": "^1.4.0", "leaflet-contextmenu": "^1.4.0",
"leaflet-editable": "^1.2.0", "leaflet-editable": "^1.2.0",
"leaflet-editinosm": "0.2.3", "leaflet-editinosm": "0.2.3",
"leaflet-formbuilder": "0.2.9", "leaflet-formbuilder": "0.2.10",
"leaflet-fullscreen": "1.0.2", "leaflet-fullscreen": "1.0.2",
"leaflet-hash": "0.2.1", "leaflet-hash": "0.2.1",
"leaflet-i18n": "0.3.5", "leaflet-i18n": "0.3.5",

View file

@ -755,8 +755,8 @@ U.Marker = L.Marker.extend({
callback: function () { callback: function () {
if (!this._latlng.isValid()) { if (!this._latlng.isValid()) {
U.Alert.error(L._('Invalid latitude or longitude')) U.Alert.error(L._('Invalid latitude or longitude'))
builder.resetField('_latlng.lat') builder.restoreField('_latlng.lat')
builder.resetField('_latlng.lng') builder.restoreField('_latlng.lng')
} }
this.zoomTo({ easing: false }) this.zoomTo({ easing: false })
}, },

View file

@ -456,6 +456,7 @@ L.FormBuilder.BlurInput.include({
L.FormBuilder.Input.prototype.build.call(this) L.FormBuilder.Input.prototype.build.call(this)
const button = L.DomUtil.create('span', 'button blur-button') const button = L.DomUtil.create('span', 'button blur-button')
L.DomUtil.after(this.input, button) L.DomUtil.after(this.input, button)
L.DomEvent.on(this.input, 'focus', this.fetch, this)
}, },
}) })
@ -903,8 +904,8 @@ L.FormBuilder.MultiChoice = L.FormBuilder.Element.extend({
}, },
fetch: function () { fetch: function () {
this.backup = this.toHTML() this.initial = this.toHTML()
let value = this.backup let value = this.initial
if (!this.container.querySelector(`input[type="radio"][value="${value}"]`)) { if (!this.container.querySelector(`input[type="radio"][value="${value}"]`)) {
value = this.options.default !== undefined ? this.options.default : this.default value = this.options.default !== undefined ? this.options.default : this.default
} }