【问题标题】:Uniforms: Creating custom field制服:创建自定义字段
【发布时间】:2019-01-16 02:34:24
【问题描述】:

我定义了以下简单架构:

import SimpleSchema from 'simpl-schema';

export const Comments = new Mongo.Collection("comments");

export const CommentsSchema = new SimpleSchema({
  comments: Array,
  "comments.$": Object,
  "comments.$.author": String
  "comments.$.text": String
})

我有一个带有AutoForm 的组件来查看/编辑这个 cmets 数组:

import {ErrorsField, SubmitField, ListField} from "uniforms-semantic";
import AutoForm from 'uniforms-semantic/AutoForm';

<AutoForm schema={CommentsSchema} onSubmit={comments => this.updateRequest(comments)} model={this.props.comments}>
  <ListField name={"comments"}/>
  <ErrorsField/>
  <SubmitField/>
</AutoForm>

this.updateRequest(...) 是一个调用 Meteor 后端函数来更新 Mongo 集合的函数。

我想自定义ListField,以便对于每条评论,"comments.$.text" TextField 显示为更大的文本框,允许换行。

目前只是单行字符串:

我考虑过重写ListField 的自定义版本,但对于这样的小改动来说,这似乎是不必要的复杂。使用制服 API 添加此类小型自定义的最佳方法是什么?

【问题讨论】:

  • 有什么理由不能只用 CSS 来做?
  • @ZackNewsham TextField 是默认为字符串生成的,它不允许换行符 AFAIK,所以我怀疑简单地编辑 CSS 是否可行。
  • 我误解了这个问题,我的道歉。以为是关于造型。

标签: reactjs meteor semantic-ui meteor-autoform simple-schema


【解决方案1】:

查看文档,您似乎可以指定 ListField 的内部工作方式。这是未经测试的,但我会猜测以下内容:

<ListField name="comments">
    <ListItemField name="$">
        <NestField name="">
            <TextField name="author" />
             <LongTextField name="text" />
        </NestField>
    </ListItemField>
</ListField>

https://github.com/vazco/uniforms/blob/master/INTRODUCTION.md#props-propagation

【讨论】:

  • 我看到了你提到的部分,但由于某种原因认为它不适用于我的情况并继续寻找更复杂的解决方案......这个 sn-p 对我来说非常有用!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-16
  • 2017-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多