如何在 angular 表单中为单选按钮添加 'tabindex'

How to add a 'tabindex' for radio buttons in angular formly

我需要在表单中向单选按钮添加特定的 tabindex。 我可以为文本字段做,但不能为单选按钮做,下面是示例代码,任何帮助表示赞赏 -

尝试在 templateOptions 上方、templateOptions 内部和选项内部三个位置添加 tabindex=1,其中 none 个可以获取焦点。

  {
    name: 'feedbackType',
    key: 'feedbackType',
    type: 'radio',
    id: 'feedbackType',
    //tabindex:'1',
    templateOptions: {
      label: Constant.feedbackForm.typeField,
      for:'feedbackType',
      required: true,
      focus: true,
      //tabindex:'1',
      options: [{
        name: 'Idea1',
        value: 'Idea1',
        //tabindex:'1'
      }, {
        name: 'Idea2',
        value: 'Idea2'
      }, {
        name: 'Idea3',
        value: 'Idea3'
      }]
    }
  },

给你。您需要使用 ngModelElAttrs。喜欢this

  {
    name: 'feedbackType',
    key: 'feedbackType',
    type: 'radio',
    id: 'feedbackType',
    ngModelElAttrs: {
      tabindex: '1'
    },
    templateOptions: {
      label: EaseConstant.feedbackForm.typeField,
      for:'feedbackType',
      required: true,
      focus: true,
      options: [{
        name: 'Idea1',
        value: 'Idea1',
      }, {
        name: 'Idea2',
        value: 'Idea2'
      }, {
        name: 'Idea3',
        value: 'Idea3'
      }]
    }
  },

如果你希望它是动态的,那么你可以这样做:

ngModelElAttrs: {
  tabindex: '{{to.tabindex}}' // to is a shortcut for `options.templateOptions`
},
expressionProperties: {
  'templateOptions.tabindex': 'someFormlyExpression' // http://docs.angular-formly.com/docs/formly-expressions
}

祝你好运!