-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FR] Support changing "Add Item" text with uiSchema #2082
Labels
Comments
Is this good feature supported? |
It is doable by using a sample from https://react-jsonschema-form.readthedocs.io/en/latest/advanced-customization/custom-templates/#arrayfieldtemplate (YMMV 🤷🏽♂️ ) CodePen: https://codepen.io/judas_brutus/pen/ExZPjRd function ArrayFieldTemplate(props) {
// There should be a better way to do this?
const {uiSchema: {"ui:options": {addText, deleteText}}} = props;
return (
<div className={props.className}>
{props.items &&
props.items.map((element) => (
<div key={element.key} className={element.className}>
<div>{element.children}</div>
{element.hasMoveDown && (
<button
onClick={element.onReorderClick(
element.index,
element.index + 1
)}
>
Down
</button>
)}
{element.hasMoveUp && (
<button
onClick={element.onReorderClick(
element.index,
element.index - 1
)}
>
Up
</button>
)}
<button onClick={element.onDropIndexClick(element.index)}>
{deleteText} // Custom Label FTW 🚀
</button>
<hr />
</div>
))}
{props.canAdd && (
<div className="row">
<p className="col-xs-3 col-xs-offset-9 array-item-add text-right">
<button onClick={props.onAddClick} type="button">
{addText} // Custom Label FTW 🚀
</button>
</p>
</div>
)}
</div>
);
}
const schema = {
type: "array",
items: {
type: "string"
}
};
const uiSchema = {
"ui:options": {
addText: "Custom Button Text",
deleteText: "Remove",
removable: false
}
};
ReactDOM.render(
<Form
schema={schema}
uiSchema={uiSchema}
ArrayFieldTemplate={ArrayFieldTemplate}
/>,
document.getElementById("app")
); |
Fixed in the v5 beta via |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prerequisites
Description
Use case: I need to change the text used for "Add Item" buttons for dynamically generated schemas (e.g. "Add Property", "Add User", etc).
Currently these buttons use a "+" button for Bootstrap and "+ Add Item" for other themes.
The documented method for changing the text is using CSS, which is theme specific and hard to manage for dynamic schemas.
Another alternative is with custom widgets, but adding custom widgets for arrays and objects adds a lot of unnecessary complexity and maintenance cost when the required change is just the button text.
I think it would be very useful to have support on uiSchema for this, it could be part of
ui:options
:The text was updated successfully, but these errors were encountered: