waibu-bootstrap 2.6.5 → 2.7.1
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.
|
@@ -1,25 +1,39 @@
|
|
|
1
1
|
import { sizes } from '../method/after-build-tag/_lib.js'
|
|
2
2
|
|
|
3
3
|
async function getInputAttr (group, formControl = true, ro) {
|
|
4
|
-
const { omit,
|
|
4
|
+
const { has, omit, forOwn, isPlainObject, isArray, get, isString } = this.app.lib._
|
|
5
|
+
const { callHandler } = this.app.bajo
|
|
6
|
+
const { req } = this.component
|
|
5
7
|
const { escape } = this.app.waibu
|
|
8
|
+
|
|
6
9
|
if (formControl) group._.class.push('form-control')
|
|
7
10
|
const attr = omit(group._, ['hint', 'label', 'wrapper'])
|
|
11
|
+
if (has(attr, 'name') && !has(attr, 'value')) {
|
|
12
|
+
if (ro) attr.value = this.formData[attr.name]
|
|
13
|
+
else {
|
|
14
|
+
const prop = this.getProp(attr.name)
|
|
15
|
+
attr.dataType = attr.dataType ?? prop.type
|
|
16
|
+
attr.dataValue = get(this.formData, `_orig.${attr.name}`, get(this.formData, attr.name))
|
|
17
|
+
if (isPlainObject(attr.dataValue) || isArray(attr.dataValue)) attr.dataValue = JSON.stringify(attr.dataValue)
|
|
18
|
+
attr.dataValue = escape(attr.dataValue)
|
|
19
|
+
attr.value = attr.dataValue
|
|
20
|
+
if (prop.values) {
|
|
21
|
+
const values = (isString(prop.values) ? await callHandler(prop.values) : [...prop.values]).map(v => {
|
|
22
|
+
if (isString(v)) v = { value: v, text: v }
|
|
23
|
+
const { camelCase } = this.app.lib._
|
|
24
|
+
const key = camelCase(`${prop.name} ${v.text}`)
|
|
25
|
+
if (req.te(key)) v.text = req.t(key)
|
|
26
|
+
return v
|
|
27
|
+
})
|
|
28
|
+
attr.options = values
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
8
32
|
if (attr.href) {
|
|
9
|
-
forOwn(this.
|
|
33
|
+
forOwn(this.formData, (v, k) => {
|
|
10
34
|
attr.href = attr.href.replace(`%7B${k}%7D`, v)
|
|
11
35
|
})
|
|
12
36
|
}
|
|
13
|
-
if (has(attr, 'name') && !has(attr, 'value') && this.component.locals.form) {
|
|
14
|
-
let prop = {}
|
|
15
|
-
const schema = get(this, 'component.locals.schema')
|
|
16
|
-
if (schema) prop = find(schema.properties, { name: attr.name }) ?? {}
|
|
17
|
-
attr.dataType = attr.dataType ?? prop.type
|
|
18
|
-
attr.dataValue = get(this, `component.locals.form._orig.${attr.name}`)
|
|
19
|
-
if (isPlainObject(attr.dataValue) || isArray(attr.dataValue)) attr.dataValue = JSON.stringify(attr.dataValue)
|
|
20
|
-
attr.dataValue = escape(attr.dataValue)
|
|
21
|
-
attr.value = escape(get(this, `component.locals.form.${attr.name}`))
|
|
22
|
-
}
|
|
23
37
|
if (sizes.includes(attr.size) && formControl) attr.class.push(`form-control-${attr.size}`)
|
|
24
38
|
return omit(attr, ['size', 'col'])
|
|
25
39
|
}
|
|
@@ -89,7 +103,6 @@ export async function buildFormRadioToggle (group, params) {
|
|
|
89
103
|
|
|
90
104
|
export async function buildFormPlaintext (group, params) {
|
|
91
105
|
const attr = await getInputAttr.call(this, group, false, true)
|
|
92
|
-
// delete attr.dataValue
|
|
93
106
|
attr.class.push('form-control-plaintext')
|
|
94
107
|
attr.readonly = ''
|
|
95
108
|
if (['object', 'array', 'text'].includes(attr.dataType)) {
|
|
@@ -97,7 +110,7 @@ export async function buildFormPlaintext (group, params) {
|
|
|
97
110
|
return await this.component.buildTag({ tag: 'textarea', attr, html: attr.value })
|
|
98
111
|
}
|
|
99
112
|
if (attr.href) {
|
|
100
|
-
const content = attr.value ? attr.value : attr.href
|
|
113
|
+
const content = attr.value ? this.component.req.t(attr.value) : attr.href
|
|
101
114
|
const html = await this.component.buildTag({ tag: 'a', attr: { href: attr.href, content } })
|
|
102
115
|
return await this.component.buildTag({ tag: 'div', attr, html })
|
|
103
116
|
}
|
|
@@ -4,8 +4,28 @@ import { build } from './form-input.js'
|
|
|
4
4
|
async function formPlaintext () {
|
|
5
5
|
return class FormPlaintext extends this.app.baseClass.MpaWidget {
|
|
6
6
|
build = async () => {
|
|
7
|
+
const { isEmpty, get } = this.app.lib._
|
|
8
|
+
const { req } = this.component
|
|
9
|
+
const { escape } = this.app.waibu
|
|
7
10
|
this.params.attr.disabled = true
|
|
11
|
+
const { name } = this.params.attr
|
|
8
12
|
if (this.params.attr.labelFloating) this.params.attr.class.push('border', 'rounded')
|
|
13
|
+
if (!isEmpty(name) && isEmpty(this.params.attr.value)) {
|
|
14
|
+
const prop = this.getProp(name)
|
|
15
|
+
const dataValue = get(this.formData, `_orig.${name}`, '')
|
|
16
|
+
let value = get(this.oldData, name, get(this.formData, name, ''))
|
|
17
|
+
const format = get(this.schema, `view.format.${name}`)
|
|
18
|
+
const formatValue = get(this.schema, `view.formatValue.${name}`)
|
|
19
|
+
const labelField = get(this.schema, `view.widget.${name}.attr.labelField`)
|
|
20
|
+
if (formatValue) value = await formatValue.call(this, value, this.formData, { req })
|
|
21
|
+
else if (prop.ref) {
|
|
22
|
+
value = this.getRefValue({ field: name, labelField, refName: this.getRefName(name) })
|
|
23
|
+
if (format && !isEmpty(value)) this.params.attr.href = await format.call(this, value, this.formData, { linkOnly: true })
|
|
24
|
+
} else if (format && !isEmpty(value)) value = await format.call(this, value, this.formData)
|
|
25
|
+
this.params.attr.dataValue = escape(dataValue)
|
|
26
|
+
this.params.attr.value = escape(value)
|
|
27
|
+
this.params.attr.dataType = prop.type
|
|
28
|
+
}
|
|
9
29
|
await build.call(this, buildFormPlaintext, this.params)
|
|
10
30
|
}
|
|
11
31
|
}
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-04-17
|
|
4
|
+
|
|
5
|
+
- [2.7.1] Bug fix in ```getInputAttr()```
|
|
6
|
+
- [2.7.1] Bug fix in ```FormPlaintext``` widget
|
|
7
|
+
|
|
8
|
+
## 2026-04-13
|
|
9
|
+
|
|
10
|
+
- [2.7.0] Rewrite ```getInputAttr()``` to not dependent to any template data, rather only depend on attributes
|
|
11
|
+
|
|
3
12
|
## 2026-04-11
|
|
4
13
|
|
|
5
14
|
- [2.6.5] Bug fix in ```form-select-ext``` widget
|