Skip to content

Commit

Permalink
max length shown for applicable fields POC
Browse files Browse the repository at this point in the history
  • Loading branch information
claravox committed Feb 21, 2025
1 parent ecdfabe commit 171f58b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion datarequest/static/datarequest/js/src/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "core-js/stable";
import "regenerator-runtime/runtime";
import React, { Component } from "react";
import { render } from "react-dom";
import Form from "@rjsf/bootstrap-4";
import Form, { FieldTemplate } from "@rjsf/bootstrap-4";
import BootstrapTable from 'react-bootstrap-table-next';
import filterFactory, { numberFilter, textFilter, selectFilter, multiSelectFilter, Comparator } from 'react-bootstrap-table2-filter';
import paginationFactory from 'react-bootstrap-table2-paginator';
Expand Down Expand Up @@ -128,6 +128,7 @@ class YodaForm extends React.Component {
onSubmit={onSubmit}
showErrorList={false}
noHtml5Validate
FieldTemplate={CustomFieldTemplate}
transformErrors={transformErrors}>
<button ref={(btn) => {this.submitButton=btn;}}
className="hidden" />
Expand Down Expand Up @@ -166,6 +167,21 @@ const CustomTitleField = ({id, title}) => {
return <div id={id} dangerouslySetInnerHTML={{ __html: title}}></div>;
};

function CustomFieldTemplate(props) {
const {id, classNames, label, help, required, description, errors, children, schema} = props;
return (schema.maxLength ?
<div className={classNames}>
<label htmlFor={id}>{label}{required ? "*" : null}</label>
{description}
{"Max length is: " + schema.maxLength}
{children}
{errors}
{help}
</div> : <FieldTemplate {...props}/>
);
}


const fields = {
DescriptionField: CustomDescriptionField,
TitleField: CustomTitleField,
Expand Down

0 comments on commit 171f58b

Please sign in to comment.