fix: 更新 CI 配置以限制推送到 main 分支,更新 README 链接,添加必填项星号插件
Some checks failed
/ surge (push) Failing after 16s
Some checks failed
/ surge (push) Failing after 16s
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import type { FormKitOptions } from '@formkit/core'
|
||||
import type { FormKitExtendableSchemaRoot, FormKitNode, FormKitOptions } from '@formkit/core'
|
||||
import { createI18nPlugin, zh } from '@formkit/i18n'
|
||||
import { genesisIcons } from '@formkit/icons'
|
||||
import { checkbox, createLibraryPlugin, form, group, range, submit, text } from '@formkit/inputs'
|
||||
@ -15,7 +15,46 @@ const theme = undefined;
|
||||
const icons = genesisIcons;
|
||||
const themePlugin = createThemePlugin(theme, icons/* , iconLoaderUrl, iconLoader */)
|
||||
|
||||
|
||||
const legends = ['checkbox_multi', 'radio_multi', 'repeater', 'transferlist'];
|
||||
function addAsteriskPlugin(node: FormKitNode) {
|
||||
if (['button', 'submit', 'hidden', 'group', 'list', 'meta'].includes(node.props.type)) return;
|
||||
|
||||
node.on('created', () => {
|
||||
const legendOrLabel = legends.includes(`${node.props.type}${node.props.options ? '_multi' : ''}`) ? 'legend' : 'label';
|
||||
|
||||
console.group(node.props.label || node.props.submitLabel)
|
||||
console.debug(`node :>> `, node);
|
||||
console.debug(`node.props.definition :>> `, node.props.definition);
|
||||
// if (typeof node.props.definition!.schema === 'function') {
|
||||
// console.debug(`node.props.definition.schema.call :>> `, node.props.definition!.schema.call(node.props.definition, {}));
|
||||
// }
|
||||
console.debug(`legendOrLabel :>> `, legendOrLabel);
|
||||
console.groupEnd()
|
||||
|
||||
if (node.props.definition?.schemaMemoKey) {
|
||||
node.props.definition.schemaMemoKey += `${node.props.options ? '_multi' : ''}_add_asterisk`;
|
||||
};
|
||||
|
||||
const schemaFn = node.props.definition!.schema!;
|
||||
node.props.definition!.schema = (sectionsSchema = {}) => {
|
||||
sectionsSchema[legendOrLabel] = {
|
||||
children: ['$label', {
|
||||
$el: 'span',
|
||||
if: '$state.required',
|
||||
attrs: {
|
||||
class: '$classes.asterisk',
|
||||
},
|
||||
children: ['*']
|
||||
}]
|
||||
}
|
||||
|
||||
return typeof schemaFn === 'function' ? schemaFn(sectionsSchema) : schemaFn
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default {
|
||||
plugins: [library, themePlugin, bindings, i18n, validation,],
|
||||
plugins: [library, themePlugin, bindings, i18n, validation, addAsteriskPlugin],
|
||||
config: { rootClasses },
|
||||
} satisfies FormKitOptions
|
Reference in New Issue
Block a user