waibu-bootstrap 2.11.0 → 2.12.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.
|
@@ -19,11 +19,13 @@ async function getInputAttr (group, formControl = true, ro) {
|
|
|
19
19
|
if (has(attr, 'name') && !has(attr, 'value')) {
|
|
20
20
|
if (ro) attr.value = this.formData[attr.name]
|
|
21
21
|
else {
|
|
22
|
-
const prop = this.getProp(attr.name)
|
|
22
|
+
const prop = this.getProp(attr.name) ?? {}
|
|
23
23
|
attr.dataType = attr.dataType ?? prop.type
|
|
24
24
|
attr.dataValue = this.formData[attr.name]
|
|
25
25
|
if (prop.values) {
|
|
26
|
-
attr.options =
|
|
26
|
+
if (this.model) attr.options = await this.model.buildPropValues(prop, { req })
|
|
27
|
+
else attr.options = (isString(prop.values) ? await callHandler(prop.values) : [...prop.values]).map(v => buildOptions(v, prop))
|
|
28
|
+
attr.options = attr.options.map(v => buildOptions(v, prop))
|
|
27
29
|
} else if (isPlainObject(attr.dataValue)) {
|
|
28
30
|
attr.dataValue = JSON.stringify(attr.dataValue)
|
|
29
31
|
attr.value = attr.dataValue
|
|
@@ -2,7 +2,7 @@ import { buildFormHint, buildFormLabel, buildFormInput } from './_lib.js'
|
|
|
2
2
|
import { sizes } from '../method/after-build-tag/_lib.js'
|
|
3
3
|
|
|
4
4
|
export async function handleInput ({ handler, group } = {}) {
|
|
5
|
-
const { trim, filter, has, omit, pull, find, get } = this.app.lib._
|
|
5
|
+
const { trim, filter, has, omit, pull, find, get, isEmpty } = this.app.lib._
|
|
6
6
|
const { attrToArray } = this.app.waibu
|
|
7
7
|
const { $ } = this.component
|
|
8
8
|
const addons = [...(this.params.addons ?? [])]
|
|
@@ -13,6 +13,14 @@ export async function handleInput ({ handler, group } = {}) {
|
|
|
13
13
|
group._.placeholder = group._.label
|
|
14
14
|
group._ = omit(group._, ['rows'])
|
|
15
15
|
}
|
|
16
|
+
let errMsg = ''
|
|
17
|
+
if (group._.name) {
|
|
18
|
+
const details = get(this, 'component.locals.error.details', [])
|
|
19
|
+
const err = find(details, { field: group._.name })
|
|
20
|
+
if (err) {
|
|
21
|
+
errMsg = `\n<div class="invalid-feedback d-block">${err.error}</div>`
|
|
22
|
+
}
|
|
23
|
+
}
|
|
16
24
|
$(`<div>${trim(this.params.html ?? '')}</div>`).find('[addon]').each(function () {
|
|
17
25
|
const position = this.attribs.addon
|
|
18
26
|
let html = trim($(this).html())
|
|
@@ -25,14 +33,7 @@ export async function handleInput ({ handler, group } = {}) {
|
|
|
25
33
|
append: [],
|
|
26
34
|
input: await handler.call(this, group)
|
|
27
35
|
}
|
|
28
|
-
if (
|
|
29
|
-
const details = get(this, 'component.locals.error.details', [])
|
|
30
|
-
const err = find(details, { field: group._.name })
|
|
31
|
-
if (err) {
|
|
32
|
-
result.input = $(result.input).addClass('is-invalid').prop('outerHTML')
|
|
33
|
-
result.input += `\n<div class="invalid-feedback">${err.error}</div>`
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
+
if (!isEmpty(errMsg)) result.input = $(result.input).addClass('is-invalid').prop('outerHTML')
|
|
36
37
|
const el = {
|
|
37
38
|
prepend: filter(addons, { position: 'prepend' }),
|
|
38
39
|
append: filter(addons, { position: 'append' })
|
|
@@ -62,6 +63,7 @@ export async function handleInput ({ handler, group } = {}) {
|
|
|
62
63
|
if (isLabelFloating) {
|
|
63
64
|
pull(group.wrapper.class, 'form-floating')
|
|
64
65
|
group.wrapper.class.push('input-group')
|
|
66
|
+
if (!isEmpty(errMsg)) group.wrapper.class.push('has-validation')
|
|
65
67
|
if (group._.size && sizes.includes(group._.size)) group.wrapper.class.push(`input-group-${group._.size}`)
|
|
66
68
|
const _attr = { class: ['form-floating'] }
|
|
67
69
|
const html = []
|
|
@@ -69,15 +71,18 @@ export async function handleInput ({ handler, group } = {}) {
|
|
|
69
71
|
if (result.prepend.length > 0) html.push(result.prepend.join('\n'))
|
|
70
72
|
html.push(await this.component.render({ tag: 'div', attr: _attr, html: `${result.input}\n${label}\n${hint}` }))
|
|
71
73
|
if (result.append.length > 0) html.push(result.append.join('\n'))
|
|
74
|
+
html.push(errMsg)
|
|
72
75
|
contents.push(html.join('\n'))
|
|
73
76
|
} else {
|
|
74
77
|
const _attr = { class: ['input-group'] }
|
|
78
|
+
if (!isEmpty(errMsg)) _attr.class.push('has-validation')
|
|
75
79
|
if (group._.size && sizes.includes(group._.size)) _attr.class.push(`input-group-${group._.size}`)
|
|
76
80
|
const html = []
|
|
77
81
|
if (result.prepend.length > 0) html.push(result.prepend.join('\n'))
|
|
78
82
|
html.push(result.input)
|
|
79
83
|
if (result.append.length > 0) html.push(result.append.join('\n'))
|
|
80
|
-
|
|
84
|
+
const item = await this.component.render({ tag: 'div', attr: _attr, html: html.join('\n') + '\n' + hint })
|
|
85
|
+
contents.push(item, errMsg)
|
|
81
86
|
}
|
|
82
87
|
return contents
|
|
83
88
|
}
|
|
@@ -3,8 +3,29 @@ import { build } from './form-input.js'
|
|
|
3
3
|
|
|
4
4
|
async function formPlaintext () {
|
|
5
5
|
return class FormPlaintext extends this.app.baseClass.MpaWidget {
|
|
6
|
-
|
|
6
|
+
reformat = async (format, value) => {
|
|
7
|
+
if (!format) return value
|
|
8
|
+
const { isPlainObject } = this.app.lib._
|
|
7
9
|
const { req } = this.component
|
|
10
|
+
const formatted = await format.call(this, value, this.formData, { req })
|
|
11
|
+
if (isPlainObject(formatted)) {
|
|
12
|
+
value = formatted.value
|
|
13
|
+
if (formatted.href) {
|
|
14
|
+
this.params.addons = this.params.addons ?? []
|
|
15
|
+
const position = 'append'
|
|
16
|
+
const attr = {
|
|
17
|
+
icon: formatted.icon ?? 'link',
|
|
18
|
+
'x-data': true,
|
|
19
|
+
'@click': `location.href='${formatted.href}'`
|
|
20
|
+
}
|
|
21
|
+
const html = await this.component.buildTag({ tag: 'btn', attr })
|
|
22
|
+
this.params.addons.push({ position, html })
|
|
23
|
+
}
|
|
24
|
+
} else value = formatted
|
|
25
|
+
return value
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
build = async () => {
|
|
8
29
|
const { isEmpty, get } = this.app.lib._
|
|
9
30
|
const { escape } = this.app.waibu
|
|
10
31
|
this.params.attr.disabled = true
|
|
@@ -19,10 +40,8 @@ async function formPlaintext () {
|
|
|
19
40
|
const labelField = get(this.schema, `view.widget.${name}.attr.labelField`)
|
|
20
41
|
if (prop.ref) {
|
|
21
42
|
const result = this.getRefValue({ field: name, labelField, refName: this.getRefName(name) })
|
|
22
|
-
if (result)
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
} else if (format) value = await format.call(this, value, this.formData, { req })
|
|
43
|
+
if (result) value = await this.reformat(format, result)
|
|
44
|
+
} else if (format) value = await this.reformat(format, value)
|
|
26
45
|
this.params.attr.dataValue = escape(dataValue)
|
|
27
46
|
this.params.attr.value = value
|
|
28
47
|
this.params.attr.dataType = prop.type
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-06-03
|
|
4
|
+
|
|
5
|
+
- [2.12.1] Bug fix in ```_lib.getInputAttr()```
|
|
6
|
+
- [2.12.1] Bug fix in ```form-input``` widget
|
|
7
|
+
|
|
3
8
|
## 2026-06-01
|
|
4
9
|
|
|
5
10
|
- [2.11.0] Remove ```params``` on all widget since it already there through ```this.params```
|
|
6
11
|
- [2.11.0] Add feature to add addons on all form inputs through schema
|
|
12
|
+
- [2.12.0] Tranform ```form-plaintext``` html as href addon if it contains link information
|
|
7
13
|
|
|
8
14
|
## 2026-05-25
|
|
9
15
|
|