waibu-bootstrap 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,8 +3,9 @@ import { sizes } from '../method/after-build-tag/_lib.js'
|
|
|
3
3
|
const trueValues = ['true', 'on', 'yes', '1', 1, true]
|
|
4
4
|
|
|
5
5
|
function getInputAttr (group, formControl = true, ro) {
|
|
6
|
-
const { omit, get, set, isPlainObject, isArray, isString, has, forOwn } = this.app.lib._
|
|
6
|
+
const { omit, get, set, isPlainObject, isArray, isString, has, forOwn, find } = this.app.lib._
|
|
7
7
|
const { escape } = this.app.waibu
|
|
8
|
+
const { req } = this.component
|
|
8
9
|
if (formControl) group._.class.push('form-control')
|
|
9
10
|
const attr = omit(group._, ['hint', 'label', 'wrapper'])
|
|
10
11
|
if (attr.href) {
|
|
@@ -13,7 +14,10 @@ function getInputAttr (group, formControl = true, ro) {
|
|
|
13
14
|
})
|
|
14
15
|
}
|
|
15
16
|
if (has(attr, 'name') && !has(attr, 'value') && this.component.locals.form) {
|
|
16
|
-
|
|
17
|
+
let prop = {}
|
|
18
|
+
const schema = get(this, 'component.locals.schema')
|
|
19
|
+
if (schema) prop = find(schema.properties, { name: attr.name }) ?? {}
|
|
20
|
+
attr.dataType = attr.dataType ?? prop.type ?? 'auto'
|
|
17
21
|
let val = get(this, `component.locals.form.${attr.name}`)
|
|
18
22
|
if (attr.dataType === 'boolean') {
|
|
19
23
|
val = trueValues.includes(val)
|
|
@@ -26,10 +30,13 @@ function getInputAttr (group, formControl = true, ro) {
|
|
|
26
30
|
if (attr.ref) {
|
|
27
31
|
const [ref, fieldName = 'id'] = attr.ref.split(':')
|
|
28
32
|
attr.value = get(this, `component.locals.form._ref.${ref}.${fieldName}`, val)
|
|
29
|
-
} else if (attr.dataType === 'boolean') attr.value =
|
|
30
|
-
else if (has(attr, 'name') === 'lat') attr.value = escape(
|
|
31
|
-
else if (has(attr, 'name') === 'lng') attr.value = escape(
|
|
32
|
-
else
|
|
33
|
+
} else if (attr.dataType === 'boolean') attr.value = req.t(val ? 'true' : 'false')
|
|
34
|
+
else if (has(attr, 'name') === 'lat') attr.value = escape(req.format(val, attr.dataType, { latitude: true }))
|
|
35
|
+
else if (has(attr, 'name') === 'lng') attr.value = escape(req.format(val, attr.dataType, { longitude: true }))
|
|
36
|
+
else if (prop.values) {
|
|
37
|
+
const item = find(prop.values, { value: val })
|
|
38
|
+
attr.value = escape(req.format(item ? req.t(item.text) : val, attr.dataType))
|
|
39
|
+
} else attr.value = escape(req.format(val, attr.dataType))
|
|
33
40
|
} else attr.value = attr.dataValue
|
|
34
41
|
if (isArray(val)) attr.value = val.join(' ')
|
|
35
42
|
}
|
|
@@ -110,7 +117,7 @@ export async function buildFormPlaintext (group, params) {
|
|
|
110
117
|
return await this.component.buildTag({ tag: 'textarea', attr, html: attr.value })
|
|
111
118
|
}
|
|
112
119
|
if (attr.href) {
|
|
113
|
-
const content = attr.value ?
|
|
120
|
+
const content = attr.value ? attr.value : attr.href
|
|
114
121
|
const html = await this.component.buildTag({ tag: 'a', attr: { href: attr.href, content } })
|
|
115
122
|
return await this.component.buildTag({ tag: 'div', attr, html })
|
|
116
123
|
}
|
|
@@ -36,9 +36,7 @@ async function formSelectExt () {
|
|
|
36
36
|
try {
|
|
37
37
|
options = base64JsonDecode(this.params.attr.options)
|
|
38
38
|
} catch (err) {
|
|
39
|
-
options = this.params.attr.options
|
|
40
|
-
return { value: item, text: item }
|
|
41
|
-
})
|
|
39
|
+
options = this.params.attr.options
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
let opts = { plugins }
|
|
@@ -132,7 +130,7 @@ async function formSelectExt () {
|
|
|
132
130
|
this.params.attr['x-data'] = `{ ${xData.join(',\n')} }`
|
|
133
131
|
// this.params.attr['@load.window'] = 'onLoad()'
|
|
134
132
|
this.params.attr['x-init'] = 'onLoad()'
|
|
135
|
-
this.params.attr.options = options
|
|
133
|
+
if (options.length > 0) this.params.attr.options = options
|
|
136
134
|
this.params.attr = omit(this.params.attr, ['noDropdownInput', 'removeBtn', 'clearBtn', 'c-opts', 'remoteUrl', 'remoteSearchField', 'remoteLabelField', 'remoteValueField'])
|
|
137
135
|
await build.call(this, buildFormSelect, this.params)
|
|
138
136
|
}
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
- [2.4.0] Update attribute functions from ```waibu```
|
|
6
6
|
- [2.4.0] Bug fix on ```FormSelectExt``` 's static css
|
|
7
7
|
- [2.4.0] Bug fix on ```FormSelectCountry``` 's static css
|
|
8
|
+
- [2.5.0] Remove ```FormSelectCountry``` alltogther
|
|
9
|
+
- [2.5.0] Bug fix on ```FormSelectExt```'s options
|
|
10
|
+
- [2.5.0] In read only mode, auto detect value from model's values
|
|
8
11
|
|
|
9
12
|
## 2026-02-15
|
|
10
13
|
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { css, scripts } from './form-select-ext.js'
|
|
2
|
-
|
|
3
|
-
async function formSelectCountry () {
|
|
4
|
-
return class FormSelectCountry extends this.app.baseClass.MpaWidget {
|
|
5
|
-
static css = [...super.css, ...css]
|
|
6
|
-
static scripts = [...super.scripts, scripts]
|
|
7
|
-
|
|
8
|
-
constructor (options) {
|
|
9
|
-
super(options)
|
|
10
|
-
this.params.noTag = true
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
build = async () => {
|
|
14
|
-
const { readConfig } = this.app.bajo
|
|
15
|
-
const { map } = this.app.lib._
|
|
16
|
-
const { base64JsonEncode } = this.app.waibu
|
|
17
|
-
const countries = await readConfig('bajoCommonDb:/extend/dobo/fixture/country.json', { ignoreError: true, defValue: [] })
|
|
18
|
-
this.params.attr.options = base64JsonEncode(map(countries, c => {
|
|
19
|
-
return { value: c.id, text: c.name.replaceAll('\'', '') }
|
|
20
|
-
}))
|
|
21
|
-
this.params.html = await this.component.buildTag({ tag: 'formSelectExt', attr: this.params.attr, html: '' })
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export default formSelectCountry
|