Security News
CISA Brings KEV Data to GitHub
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
@mighty-justice/fields-ant
Advanced tools
Standard Ant design component interface for Field Sets
A standard library / interface for building Forms and standard CRUD components in Ant Design.
Open source, developed primarily at Mighty.
Documentation |
---|
The most common patterns in a piece of software are CRUD: Creating, reading, updating, and deleting a piece of data. Extremely common tasks like "Add a form for editing the phone number" require a lot of boiler-plate in libraries such as Ant Design.
Fields Ant seeks to make these simple components extremely easy to add using a common configuration language based around the "FieldConfig."
The fieldConfig is the basic unit that fields-ant uses to define something that should be shown or edited. There is only one required attribute in a fieldConfig, the field.
A simple example is wanting to display or edit the field phone_number
on an object.
The fieldConfig for this would be { field: 'phone_number' }
.
The components in this library use this field config by fill it in. For the example above, the filled in version looks like this:
{
disabled: false,
editComponent: function Input(props) {,
editProps: {},
field: "phone_number",
fieldConfigProp: false,
formValidationRules: {},
fromForm: function falseyToString(value) { return value || ''; },
key: "phone_number",
label: "Phone Number",
nullify: false,
populateFromSearch: false,
populateNameFromSearch: false,
readOnly: false,
render: function (value, _fieldConfig, _model) { return func(value); },
required: false,
showLabel: true,
skipFieldDecorator: false,
toForm: function falseyToString(value) { return value || ''; },
type: "phone",
writeOnly: false,
}
Two interesting things about this example:
phone
was inferred by the library because the field has phone
in the name.You can play with fillInFieldConfig
on the FieldConfig Preview page of this documentation.
The second most important attribute of a fieldConfig is the 'type'. This is a way of applying a common
set of 'preset' of attributes. For example, type: 'money'
includes an appropriate render function,
edit component, validator, and sets falsey values to null instead of an empty string.
field: Field can be any string which would be supported in lodash get, like 'name', 'lawfirm.name', or 'lawfirms[0].name'.
type: This is a way of applying a common set of 'preset' of attributes. For example, type: 'money'
includes
an appropriate render function, edit component, validator, and sets falsey values to null instead of empty string.
Antd.Form.Item
.field
is usually very good, but sometimes you want something completely
different.Attributes for filtering this field out. These can be very useful if you're using one fieldSet, but want something to display only in the form, not in the form, or based one one of the other fields. One example of this is showing a law firm contact only when a law firm is selected. Another is making a non-editable field read only.
Attributes for controlling how fieldConfig works in form.
onChange
prop.Validation rules are documented here: https://ant.design/components/form/#Validation-Rules
Alternatively, we support a fieldsValidator
attribute in the validation rule which takes (value, fieldConfig, model)
and returns a boolean. This is much simpler to write than the default validation function option.
Attributes for controlling how fieldConfig works in table
These enable features in objectSearchCreate explained in the documentation for that type.
These are technical and you can safely ignore them
Antd.Col
.fieldConfig
prop will be passed into editComponent
.editComponent
will be mounted without an Ant Design Table fieldDecorator.
A formManager
and formModel
prop will be passed into the editComponent and you will be responsible for using
FormItem
yourself.A fieldSet is just a collection of fieldConfigs. There are two types of fieldSet: Simple and Complex.
A simple fieldSet is just an array of fieldConfigs, whereas a complex fieldSet is an object. The fields
attribute of that object is An array of fieldConfigs, but the rest of the object can contain information
about the fieldSet:
FieldSet
Antd.Row
.Most components in fields-ant take a fieldSets
prop which is an array of complex and/or simple fieldSets.
The two core components are the Card and the Form. Most of the other components are either a building block or a variant of these two. Here are to extremely simple examples:
<Card
fieldSets={[[
{ field: 'phone_number', }
]]}
model={{ phone_number: '5558605309' }}
/>
This card will show the label and will format the phone number in the model.
<Form
fieldSets={[[
{ field: 'phone_number', }
]]}
/>
This form will allow the user to type in a phone number and will validate it.
There are obviously a LOT more attributes that can be added to these fieldSets and props to be passed to these and other components. To read about other attributes, I recommend checking out the IFieldConfigBase definition in interfaces.ts and to see component props, see the components section of our online documentation.
yarn add @mighty-justice/fields-ant
npm install @mighty-justice/fields-ant
"antd": "^3.0.0",
"lodash": "^4.0.0",
"mobx": "^4.0.0 || ^5.0.0",
"mobx-react": "^5.0.0",
"moment": "^2.0.0",
"react": "^16.0.0"
npm install --save-dev @mighty-justice/fields-ant
yarn add --dev @mighty-justice/fields-ant
We accept new issues and pull requests from anyone!
npm run deploy
This will run checks for test
, lint
, build
, bump the version number,
publish to npm, and publish the docs to Github Pages.
Gotchas:
npm install
or yarn install
firstFAQs
Standard Ant design component interface for Field Sets
We found that @mighty-justice/fields-ant demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.
Security News
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.