最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular Formly: how to add class to wrapping div - Stack Overflow

programmeradmin1浏览0评论
<formly-form model="vm.model" fields="step.inputs" options="vm.options">
    <div style="text-align:right">
        <button type="submit" wz-next class="btn btn-primary submit-button" ng-disabled="innerForm.$invalid">Næste</button>
    </div>
</formly-form>

Using the above markup would generate a more og less standard formly form, but my issue is that based on values set in the templateOptions of my fields, i want to be able to add a class to the formly-field div.

So an example would be:

inputs: [
    {
        key: 'someKey',
        type: 'input',
        templateOptions: {
            label: 'some text',
            class: 'floatLeft'
        }
    },
    {
        key: 'someKey',
        type: 'input',
        templateOptions: {
            label: 'some text',
            class: 'floatRight'
        }
    }]

Should generate 2 formly-fields like these:

<div formly-field ng-repeat="field in fields " class="floatLeft ..." ...>...</div>
<div formly-field ng-repeat="field in fields " class="floatRight ..." ...>...</div>

So the class gets added to the div, i've tried using wrappers, but they dont wrap around the formly-field div. And since step.inputs is an array of fields, im not sure how to do it.

<formly-form model="vm.model" fields="step.inputs" options="vm.options">
    <div style="text-align:right">
        <button type="submit" wz-next class="btn btn-primary submit-button" ng-disabled="innerForm.$invalid">Næste</button>
    </div>
</formly-form>

Using the above markup would generate a more og less standard formly form, but my issue is that based on values set in the templateOptions of my fields, i want to be able to add a class to the formly-field div.

So an example would be:

inputs: [
    {
        key: 'someKey',
        type: 'input',
        templateOptions: {
            label: 'some text',
            class: 'floatLeft'
        }
    },
    {
        key: 'someKey',
        type: 'input',
        templateOptions: {
            label: 'some text',
            class: 'floatRight'
        }
    }]

Should generate 2 formly-fields like these:

<div formly-field ng-repeat="field in fields " class="floatLeft ..." ...>...</div>
<div formly-field ng-repeat="field in fields " class="floatRight ..." ...>...</div>

So the class gets added to the div, i've tried using wrappers, but they dont wrap around the formly-field div. And since step.inputs is an array of fields, im not sure how to do it.

Share Improve this question asked Sep 2, 2015 at 16:09 Christian BekkerChristian Bekker 1,8675 gold badges27 silver badges43 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

To add classes to the formly-field div, you simply specify a className on the root of your field configuration. So:

inputs: [
    {
        key: 'someKey',
        type: 'input',
        className: 'floatRight',
        templateOptions: {
            label: 'some text'
        }
    },
    {
        key: 'someKey',
        type: 'input',
        className: 'floatRight',
        templateOptions: {
            label: 'some text'
        }
    }
]
发布评论

评论列表(0)

  1. 暂无评论