Property
Properties are AdminJS's representation of your model's fields.
Introduction
Properties are AdminJS's representation of your model's fields. Every adapter used by AdminJS must export a Property
which is an extension of BaseProperty. In this section you will learn how to override default settings of your resource's properties as well as how to add new properties to your resource using it's configuration object.
Customizing properties
This tutorial will cover how you can use different Property options to customize your properties.
Creating custom properties
Let's assume that you would like to add a new property called randomPicture
to your User
resource which would show a randomly generated picture in your User
resource's list
and show
actions.
First, let's create a custom React component which will display the image:
Every property can be further customized. That will be covered in the later parts of this section.
Displaying a tooltip next to a field in forms
If a field that you are displaying in your form might require additional information to fill in correctly, you may want to use a description
option in your property's configuration. This option allows you to set a message that will be displayed after hovering over a question mark icon next to a label in your form.
You can also use a translation key and define a translation in locale.
Defining available values for user to choose from
Although this is not required most of the time because your adapter of choice should be able to load enum values from your models, there can still be a situation where you want a field to be a selection instead of a regular text input. This can be done through availableValues
option.
Passing props into HTML element/component
There could be a case where you want to pass extra props to the React component or HTML element which AdminJS is using to render a form field. You can use props
for this:
The example above sets textarea's rows
prop to 20
, the default being 2
.
Last updated