我正在尝试使用react-json schema-form创建一个表单。我是新的自定义模板相同。我希望在表单中的所有小部件都在一行中。如何做到这一点?
我尝试了下面的(组件),它来自他们网站上的自定义对象,但没有得到想要的结果。
import React from 'react';
import Form from 'react-jsonschema-form';
/* this is my schma*/
const AdHocCheckSchema = {
title: "search",
type: "object",
required: ["searchKeyword", "country"],
properties: {
searchKeyWord: {
type: "string",
title: "Search Keyword"
},
country: {
type: "string",
title: "country",
enum: [
"a",
"b"
],
enumNames: [
"a",
"b"
]
}
}
};
/*this is the ui schema*/
const adHocCheckUiSchema = {
"ui:order": [
"searchKeyWord",
"country"
],
"country": {
"ui:widget": "select"
}
};
function CustomTemplate(props)
{
return (
<div>
{props.title}
{props.description}
{props.properties.map(
element =>
<div className="property-wrapper">{element.content}</div>)}
</div>
);
}
const AdHocCheckComponent = () => {
return (
<Form
className="tp-adhoccheck__horizontal"
schema={AdHocCheckSchema}
uiSchema={adHocCheckUiSchema}
CustomTemplate={CustomTemplate}
/>
);
};
export default AdHocCheckComponent;我不知道如何使输入字段,选择小工具和按钮在同一行。到目前为止,它看起来像是一个默认表单,一行接一行。
发布于 2019-05-13 05:22:55
您可以通过模板自定义每个字段的外观。考虑到表单作为对象提交,您可能需要调整ObjectFieldTemplate:https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/#object-field-template
事实上,如果你去他们的游乐场(https://mozilla-services.github.io/react-jsonschema-form/,顶部的“自定义对象”选项卡链接),你会看到所有的字段都在一行中(如果你的屏幕分辨率足够高,否则它们会换到后面的行中)。他们实现此效果的源代码(通过自定义ObjectFieldTemplate组件(位于以下位置:https://github.com/mozilla-services/react-jsonschema-form/blob/master/playground/samples/customObject.js
function ObjectFieldTemplate({ TitleField, properties, title, description }) {
return (
<div>
<TitleField title={title} />
<div className="row">
{properties.map(prop => (
<div
className="col-lg-2 col-md-4 col-sm-6 col-xs-12"
key={prop.content.key}>
{prop.content}
</div>
))}
</div>
{description}
</div>
);
}发布于 2019-07-08 19:12:53
我使用了customFieldTemplate和flex-box,可以把它排成一行。
export const customFieldTemplate = (props) => {
const {id, label, classNames, required, errors, children} = props;
return (
<div className={classNames}>
<label className="field_label" htmlFor={id}>
<span className="required-field">
{required ? '*' : null}
</span>
{label}
</label>
{children}
{errors}
</div>
);
};
https://stackoverflow.com/questions/55571931
复制相似问题