wip(forms): remove defaultOptions from builder

This commit is contained in:
David Larlet 2024-03-01 11:07:28 -05:00 committed by Yohan Boniface
parent 4cdf682706
commit 5295e931a5
2 changed files with 45 additions and 34 deletions

View file

@ -103,11 +103,15 @@ U.FeatureMixin = {
L._('Feature properties')
)
let builder = new U.FormBuilder(this, ['datalayer'], {
let builder = new U.FormBuilder(
this,
[['datalayer', { handler: 'DataLayerSwitcher' }]],
{
callback: function () {
this.edit(e)
}, // removeLayer step will close the edit panel, let's reopen it
})
}
)
container.appendChild(builder.build())
const properties = []

View file

@ -977,19 +977,8 @@ U.FormBuilder = L.FormBuilder.extend({
className: 'umap-form',
},
defaultOptions: {
color: { handler: 'ColorPicker' },
fillColor: { handler: 'ColorPicker' },
iconUrl: { handler: 'IconUrl' },
datalayer: { handler: 'DataLayerSwitcher' },
datalayersControl: { handler: 'DataLayersControl' },
licence: { handler: 'LicenceChooser' },
},
computeDefaultOptions: function () {
for (let [key, schema] of Object.entries(U.SCHEMA)) {
schema = L.Util.extend({}, schema, this.defaultOptions[key])
if (!schema.handler) {
if (schema.type === Boolean) {
if (schema.nullable) schema.handler = 'NullableChoices'
else schema.handler = 'Switch'
@ -999,7 +988,10 @@ U.FormBuilder = L.FormBuilder.extend({
if (schema.step) schema.handler = 'Range'
else schema.handler = 'IntInput'
} else if (schema.choices) {
const text_length = schema.choices.reduce((acc, [value, label]) => acc + label.length, 0)
const text_length = schema.choices.reduce(
(acc, [value, label]) => acc + label.length,
0
)
// Try to be smart and use MultiChoice only
// for choices where labels are shorts…
if (text_length < 40) {
@ -1008,6 +1000,21 @@ U.FormBuilder = L.FormBuilder.extend({
schema.handler = 'Select'
schema.selectOptions = schema.choices
}
} else {
switch (key) {
case 'color':
case 'fillColor':
schema.handler = 'ColorPicker'
break
case 'iconUrl':
schema.handler = 'IconUrl'
break
case 'datalayersControl':
schema.handler = 'DataLayersControl'
break
case 'licence':
schema.handler = 'LicenceChooser'
break
}
}
// FormBuilder use this key for the input type itself