Developing a Custom Form Field for Liferay 7.2
React-based custom form fields can be developed for Liferay 7.3 and Liferay 7.4. See Writing Custom Form Field Types to learn how. Liferay 7.2 used a different frontend technology, based on MetalJS and Soy closure templates. In this tutorial you can learn to adapt the React-based Acme C2P9 Slider field to run on a Liferay 7.2 installation.
Adjusting the Acme C2P9 Slider to Run on Liferay 7.2
Liferay 7.2 used a different frontend framework for custom form fields. To adjust the Acme C2P9 Slider field in order to run it on Liferay 7.2,
-
Download and unzip the Custom Forms Field Type project.
-
Open the
liferay-c2p9.zip/gradle.properties
file and change the lineto
-
Open the
liferay-c2p9.zip/settings.gradle
file and change the lineto
-
Open the
liferay-c2p9.zip/c2p9-impl/build.gradle
file and add the lines -
Open the
liferay-c2p9.zip/c2p9-impl/package.json
file. Begin by replacing thedevDependencies
linewith these two lines:
Then replace the existing
scripts
content (two lines) with these three lines: -
Open the
liferay-c2p9.zip/c2p9-impl/bnd.bnd
file and add these lines: -
Replace the contents of
liferay-c2p9.zip/c2p9-impl/.babelrc.js
withCheckpoint: The project is reconfigured to expect the 7.2 frontend framework, so you must replace the frontend of the form field project.
-
Remove the existing
Slider.es.js
file and create these three files to replace it:-
Slider.es.js
: the new slider component using the MetalJS + Soy frontend. -
Slider.soy
: the Soy template for the field. -
SliderRegister.soy
: the registration code for the Slider’s Soy template.
-
-
A minor adjustment to the
DDMFormFieldType
is needed: the identifier for the field (thename
) cannot have a hyphen (-
) because it is referenced as a String literal in the Soy template. Open theC2P9DDMFormFieldType
class and remove the hyphen from- the component property
ddm.form.field.type.name
- the String returned by
getName
The value in both locations is now
c2p9slider
. - the component property
-
Once the project’s frontend is replaced, deploy it to a running Liferay 7.2.
- To start a Liferay 7.2 Docker container run
- To deploy the reconfigured form field project, go to the
liferay-c2p9.zip
folder and run
-
Confirm the deployment in the Liferay Docker container console.
The form field is deployed and ready to use on Liferay 7.2.