You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Power Apps画布表单中实现支持多选及手动输入的SharePoint Choice字段

SharePoint「Types」多选手动输入列的Power Apps画布表单实现方案

核心逻辑基础

SharePoint支持手动输入的多选Choice列,存储格式为包含Value字段的记录集合(无论值是预设选项还是自定义输入)。Power Apps中只需将用户的预设选择、自定义输入合并为同结构的集合,再绑定到表单对应字段即可覆盖所有场景。

控件假设(基于常见UI配置)

假设你已具备以下控件(可根据实际UI调整命名):

  • cmb_Types:允许多选的下拉框,Items属性绑定预设选项:Choices(你的数据源.Types)
  • txt_CustomType:自定义值输入框
  • col_SelectedTypes:全局集合,用于存储所有选中的预设/自定义值
  • gal_SelectedItems:展示所有选中项的画廊(可选,用于删除操作)

分场景逻辑实现

1. 仅选择单个/多个预设选项

  • 开启cmb_Types的多选属性(Allow multiple selections设为true)
  • 对应DataCard的Update属性直接绑定下拉框选中项:
    cmb_Types.SelectedItems
    

2. 选择预设选项+输入自定义值

  1. 同步预设选择到集合:
    • 设置cmb_Types的OnChange属性:
      ClearCollect(col_SelectedTypes, cmb_Types.SelectedItems)
      
  2. 添加自定义值到集合:
    • 给输入框配套"添加"按钮,设置OnSelect属性(含重复值校验):
      If(
          Not(IsBlank(txt_CustomType.Text)) && Not({Value: txt_CustomType.Text} in col_SelectedTypes),
          Collect(col_SelectedTypes, {Value: txt_CustomType.Text});
          Reset(txt_CustomType)
      )
      
  3. 绑定集合到表单字段:
    • DataCard的Update属性设为:
      col_SelectedTypes
      

3. 仅输入自定义值

  • 逻辑和场景2一致,用户无需选择下拉框,直接输入自定义值后点击添加按钮即可。若要自动添加,可设置txt_CustomType的OnChange属性:
    If(
        Not(IsBlank(txt_CustomType.Text)) && Not({Value: txt_CustomType.Text} in col_SelectedTypes),
        Collect(col_SelectedTypes, {Value: txt_CustomType.Text});
        Reset(txt_CustomType)
    )
    
  • DataCard的Update属性仍为col_SelectedTypes

表单模式适配(新增/编辑/视图)

新增模式(NewForm)

  • 在表单的OnNew事件中初始化集合:
    Clear(col_SelectedTypes)
    

编辑模式(EditForm)

  • 加载现有数据到集合和下拉框:
    • 表单OnEdit事件:
      ClearCollect(col_SelectedTypes, ThisItem.Types)
      
    • 设置cmb_Types的DefaultSelectedItems属性,自动选中已有预设选项:
      Filter(col_SelectedTypes, Value in Choices(你的数据源.Types).Value)
      
  • 画廊gal_SelectedItems的Items属性设为col_SelectedTypes,添加删除按钮,OnSelect属性:
    Remove(col_SelectedTypes, ThisItem)
    

视图模式(ViewForm)

  • 将DataCard的DisplayMode设为DisplayMode.View
  • 用标签或画廊展示所有值:
    • 标签的Text属性:
      Concat(ThisItem.Types, Value, ", ")
      

内容的提问来源于stack exchange,提问作者microsoftdeveloperdesigner

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 10:12:29