diff --git a/src/components/Form/AutoDataForm/utils.js b/src/components/Form/AutoDataForm/utils.js index 5976e8751..55deadb1b 100644 --- a/src/components/Form/AutoDataForm/utils.js +++ b/src/components/Form/AutoDataForm/utils.js @@ -197,22 +197,32 @@ export class FormFieldGenerator { return field } - afterGenerateField(field) { - field.label = toSentenceCase(field.label) - - if (field.placeholder) { - field.el.placeholder = field.placeholder - } - + setChoicesTips(field, fieldMeta, fieldRemoteMeta) { // 设置 checkbox 的 tips - if (field.tips && ['checkbox-group', 'radio-group'].indexOf(field.type) !== -1) { + if (['checkbox-group', 'radio-group'].indexOf(field.type) !== -1) { field.options.map(option => { - if (!option.tip && field.tips[option.value]) { + if (!option.tip && field.tips) { option.tip = field.tips[option.value] } + if (!option.tip) { + const match = option.label.match(/^(.+?)\s*\((.*?)\)$/) + if (match) { + option.label = match[1] + option.tip = match[2] + } + } }) } + } + + afterGenerateField(field) { + field.label = toSentenceCase(field.label) + + if (field.placeholder) { + field.el.placeholder = field.placeholder + } + this.setChoicesTips(field) return field }