InputText 输入框

基本使用

```schema: scope=”body” { “type”: “form”, “api”: “/api/mock2/form/saveForm”, “body”: [ { “name”: “text”, “type”: “input-text”, “label”: “text” } ] }

  1. ## 不同类型
  2. 配置`type`可以支持不同格式的文本输入框
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "api": "/api/mock2/form/saveForm",
  7. "body": [
  8. {
  9. "name": "text",
  10. "type": "input-text",
  11. "label": "text"
  12. },
  13. {
  14. "type": "divider"
  15. },
  16. {
  17. "type": "input-url",
  18. "name": "url",
  19. "label": "链接"
  20. },
  21. {
  22. "type": "divider"
  23. },
  24. {
  25. "type": "input-email",
  26. "name": "email",
  27. "label": "邮箱"
  28. },
  29. {
  30. "type": "divider"
  31. },
  32. {
  33. "type": "input-password",
  34. "name": "password",
  35. "label": "密码"
  36. }
  37. ]
  38. }

附加组件

可以配置addOn,附带附加组件,比如 button,还能设置 icon。

```schema: scope=”body” { “type”: “form”, “api”: “/api/mock2/form/saveForm”, “body”: [ { “name”: “text”, “type”: “input-text”, “label”: “text”, “addOn”: { “type”: “button”, “icon”: “https://suda.cdn.bcebos.com/images%2F2021-01%2Fsearch.svg“, “label”: “搜索” } } ] }

  1. ## 可清除
  2. 通过 `"clearable": true` 可以设置文本可清除
  3. ```schema: scope="body"
  4. {
  5. "type": "form",
  6. "api": "/api/mock2/form/saveForm",
  7. "body": [
  8. {
  9. "name": "text",
  10. "type": "input-text",
  11. "label": "text",
  12. "clearable": true
  13. }
  14. ]
  15. }

选择器模式

配置options即可支持选择器模式。

```schema: scope=”body” { “type”: “form”, “api”: “/api/mock2/form/saveForm”, “body”: [ { “name”: “text”, “type”: “input-text”, “label”: “text”, “options”: [ { “label”: “aa”, “value”: “aa” }, { “label”: “bb”, “value”: “bb” }, { “label”: “cc”, “value”: “cc” }, { “label”: “dd”, “value”: “dd” } ] } ] }

  1. 选择器模式下,支持部分选择器组件支持的配置项,具体请查看下面的属性表。如:source autoComplete 都支持
  2. ## 限制只能选择预设
  3. 配置 options 并且配置 creatable: false
  4. ```schema: scope="body"
  5. {
  6. "type": "form",
  7. "api": "/api/mock2/form/saveForm",
  8. "body": [
  9. {
  10. "name": "text",
  11. "type": "input-text",
  12. "label": "text",
  13. "creatable": false,
  14. "options": [
  15. {
  16. "label": "OptionA",
  17. "value": "a"
  18. },
  19. {
  20. "label": "OptionB",
  21. "value": "b"
  22. },
  23. {
  24. "label": "OptionC",
  25. "value": "c"
  26. },
  27. {
  28. "label": "OptionD",
  29. "value": "d"
  30. }
  31. ]
  32. }
  33. ]
  34. }

多选模式

配置 multiple: true

```schema: scope=”body” { “type”: “form”, “api”: “/api/mock2/form/saveForm”, “debug”: true, “body”: [ { “name”: “text”, “type”: “input-text”, “label”: “text”, “multiple”: true, “options”: [ { “label”: “OptionA”, “value”: “a” }, { “label”: “OptionB”, “value”: “b” }, { “label”: “OptionC”, “value”: “c” }, { “label”: “OptionD”, “value”: “d” } ]

  1. }
  2. ]

}

  1. ## 前缀和后缀
  2. ```schema: scope="body"
  3. {
  4. "type": "form",
  5. "api": "/api/mock2/form/saveForm",
  6. "data": {
  7. "unit": "MB"
  8. },
  9. "body": [
  10. {
  11. "name": "text",
  12. "type": "input-text",
  13. "label": "text",
  14. "prefix": "¥",
  15. "suffix": "RMB"
  16. },
  17. {
  18. "name": "prefix",
  19. "type": "input-text",
  20. "label": "text",
  21. "prefix": "¥"
  22. },
  23. {
  24. "name": "suffix",
  25. "type": "input-text",
  26. "label": "text",
  27. "suffix": "${unit}"
  28. }
  29. ]
  30. }

支持数据映射

显示计数器

```schema: scope=”body” { “type”: “form”, “body”: [ { “name”: “a”, “type”: “input-text”, “label”: “A”, “showCounter”: true, “placeholder”: “请输入” }, { “name”: “b”, “type”: “input-text”, “label”: “B”, “showCounter”: true, “maxLength”: 100, “placeholder”: “请输入” } ] }

  1. ## 自动转换值
  2. 可以配置 transform,来自动转换值,支持转小写或大写。
  3. > 注意下面第一个示例,只有输入的内容才会触发 transform,下拉框选中的值是不会处理的。
  4. ```schema: scope="body"
  5. {
  6. "type": "form",
  7. "debug": true,
  8. "body": [
  9. {
  10. "name": "lower",
  11. "type": "input-text",
  12. "label": "转换小写",
  13. "placeholder": "输入的英文自动转为小写",
  14. "transform": {
  15. "lowerCase": true
  16. },
  17. "multiple": true,
  18. "options": ["APPLE", "ORANGE", "WATERMELON"],
  19. },
  20. {
  21. "name": "upper",
  22. "type": "input-text",
  23. "label": "转换大写",
  24. "placeholder": "输入的英文自动转为大写",
  25. "transform": {
  26. "upperCase": true
  27. }
  28. }
  29. ]
  30. }

属性表

当做选择器表单项使用时,除了支持 普通表单项属性表 中的配置以外,还支持下面一些配置

属性名 类型 默认值 说明
options Array<object>Array<string> 选项组
source stringAPI 动态选项组
autoComplete stringAPI 自动补全
multiple boolean 是否多选
delimiter string , 拼接符
labelField string "label" 选项标签字段
valueField string "value" 选项值字段
joinValues boolean true 拼接值
extractValue boolean false 提取值
addOn addOn 输入框附加组件,比如附带一个提示文字,或者附带一个提交按钮。
addOn.type string 请选择 textbutton 或者 submit
addOn.label string 文字说明
addOn.position `’left’ \ ‘right’` 'right' addOn 位置
addOn.xxx string 其他参数请参考按钮文档
trimContents boolean 是否去除首尾空白文本。
creatable boolean 是否可以创建,默认为可以,除非设置为 false 即只能选择选项中的值
clearable boolean 是否可清除
resetValue string "" 清除后设置此配置项给定的值。
prefix string "" 前缀
suffix string "" 后缀
showCounter boolean 是否显示计数器
minLength number 限制最小字数
maxLength number 限制最大字数
transform object 自动转换值,可选 transform: { lowerCase: true, upperCase: true }

事件表

当前组件会对外派发以下事件,可以通过onEvent来监听这些事件,并通过actions来配置执行的动作,在actions中可以通过event.data.xxx事件参数变量来获取事件产生的数据,详细请查看事件动作

事件名称 事件参数 说明
click event.data.value: string 输入值 点击输入框时触发,只针对选择器模式的输入框有效
enter event.data.value: string 输入值 回车时触发,只针对选择器模式的输入框有效
focus event.data.value: string 输入值 输入框获取焦点时触发
blur event.data.value: string 输入值 输入框失去焦点时触发
change event.data.value: string 输入值 值变化时触发

动作表

当前组件对外暴露以下特性动作,其他组件可以通过指定actionType: 动作名称componentId: 该组件id来触发这些动作,动作配置可以通过args: {动作配置项名称: xxx}来配置具体的参数,详细请查看事件动作

动作名称 动作配置 说明
clear - 清空
reset - 重置
focus - 获取焦点
reload - 刷新(重新加载),只针对配置了source的输入框有效
setValue value: string 更新的值 更新数据,开启multiple多选时用,分隔