Creating Form Fragments

Liferay 7.4 U45+/GA45+

The form components fragments are for building your object’s forms in a content page. If Liferay’s form fragments don’t satisfy your use case, create your own to achieve the desired design and functionality for your forms.

To create form fragments,

  1. Open the Site Menu (Site Menu) and go to DesignFragments.

  2. Click Plus (Plus Button) to create a Fragment Set for organizing your form fragments.

  3. Click Add (Add Button), select the Form Fragment type, and click Next.

    Select the form fragment type and click Next.

  4. Enter a name.

  5. Select the field types to allow in the fragment.

    If you select CAPTCHA, you cannot select other field types. Otherwise, you can select any combination of fields.

    Select the field types the fragment supports.

  6. Click Add. This creates a draft fragment and shows you to the fragment edit page.

  7. In the Code tab, add HTML, CSS, and JavaScript for your fragment.

    In the Code tab, add HTML, CSS, and JavaScript for your fragment.

    Note

    You can map the submit button fragment’s text using mapping settings.

    To create a button with link settings for redirection, add type="button" to the button fragment.

  8. (Optional) In the Configuration tab, use JSON to configure the fragment and add options to it. See Fragment Configuration Types Reference to learn more about different fragment configuration types.

    In the Configuration tab, use JSON to configure the fragment and add options to it

  9. Click Publish.

Now use your form fragment to build forms in content pages. See Using Fragments to Build Forms for more information.

Supported Field Types Reference

Field TypeDescription
booleanBoolean field.
captchaUsers must verify they are human before submissions.
dateDate field.
fileAdds support for attaching files.
htmlAdds a CKEditor for adding rich text.
multiselectSelect from a list of checkboxes.
numberNumeric fields.
relationshipDefine object relationships.
selectSelect options from drop-down lists.
textAdds support for text fields.

Using the input Variable with Form Fragments

Form fragments include the input variable for use with each fragment’s JavaScript and FreeMarker code. This variable contains the properties for configuring the fragment.

Input Variable Properties Reference

PropertyTypeDescription
fieldTypesstringField type mapped to the input.
namestringInput’s name. To create a fragment, the user must define this property.
requiredbooleanWhether the input is required.
valuestringField’s value.
labelstringInput’s label.
showLabelbooleanLabel visibility.
errorMessagestringForm submission errors.
helpTextstringUI help message for the form field. If undefined, this property is empty.
showHelpTextbooleanHelp text visibility.
attributesobjectOptions added to the fragment for specific input types.

Attributes for file Input

PropertyTypeDescription
allowedFileExtensionsstringAllowed file extensions. If Show Supported File Info is enabled, the allowed extensions appear in the field’s help text.
maxFileSizenumberMaximum upload size in megabytes. If Show Supported File Info is enabled, the maximum allowed size appears in the field’s help text.
selectFromDocumentLibrarybooleanWhether users can select files from the document library. This is set in the object’s attachment field.
selectFromDocumentLibraryURLstring or undefinedIf selectFromDocumentLibrary is true, this property contains the URL for rendering the corresponding ItemSelector.

Attributes for number Input

PropertyTypeDescription
dataTypeinteger or decimalChoose integer or decimal numbers.
maxnumber or undefinedMaximum number allowed.
minnumber or undefinedMinimum number allowed.
stepstring or undefinedString value that can be used with the HTML input “step” attribute to indicate the maximum allowed precision.

Attributes for relationship Input

PropertyTypeDescription
relationshipLabelFieldNamestringField name of the related object used as the label.
relationshipValueFieldNamestringField name of the related object used as the value.
relationshipURLstringURL used to fetch options from the API. The API response uses Liferay’s headless list format, including pagination. Pass additional parameters to query the response.

Attributes for select Input

PropertyTypeDescription
optionsArray<{label: string, value: string}>List of available options.

Capabilities

Product

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy