How to create a read-only field in a form

Issue

  • When you are creating a form, sometimes you want to create a field that is read-only because, for example, it is automatically populated by taking information from an API or a database, and you don't want the user to modify it.

  • From Liferay, it was thought to introduce this option, you can see it in the following Feature Request LPS-193313, but it was discarded because it would produce an inconsistency of behavior between the UI and the API that they do not see safe.

Environment

  • Liferay DXP 7.1
  • Liferay DXP 7.2
  • Liferay DXP 7.3
  • Liferay DXP 7.4
  • Quarterly Release

Resolution

This workaround allows you to modify this property to create read-only fields:

  1. Create the form as you wish, including the field or fields that you want to be read-only and publish the form.
  2. Go to the 3 dots on the top bar and click on the import/export option. Configure the export and the content as you want and click Export.
  3. Download the .lar file and open it. Go to the file ddm-form.json which is in a similar route to this one: /group/20117/com.liferay.dynamic.data.mapping.model.DDMStructure/34408/
  4. Open that file and change the “readOnly” value, set it to “true”, from the field that you want and save the file.
  5. Now import that .lar, and you will have your form with a read only field.
この記事は役に立ちましたか?
0人中0人がこの記事が役に立ったと言っています