Skip to content

Commit 3080e96

Browse files
committed
update documentation for display constraint
1 parent 4f8387e commit 3080e96

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

grails-doc/src/en/ref/Constraints.adoc

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,62 @@ Some constraints have no impact on persistence but customize the scaffolding. It
176176
|===
177177
|Constraint|Description
178178

179-
|display|Boolean that determines whether the property is displayed in the scaffolding views. If `true` (the default), the property _is_ displayed.
179+
|display|Controls whether and where the property is displayed in scaffolding views. Accepts a boolean or a `DisplayType` enum value (see below).
180180
|editable|Boolean that determines whether the property can be edited from the scaffolding views. If `false`, the associated form fields are displayed in read-only mode.
181181
|format|Specify a display format for types that accept one, such as dates. For example, 'yyyy-MM-dd'.
182182
|password|Boolean indicating whether this is property should be displayed with a password field. Only works on fields that would normally be displayed with a text field.
183183
|widget|Controls what widget is used to display the property. For example, 'textarea' will force the scaffolding to use a <textArea> tag.
184184
|===
185185

186+
==== The display Constraint
187+
188+
The `display` constraint controls whether a property appears in scaffolded views. It accepts either a boolean value or a `DisplayType` enum value for fine-grained control.
189+
190+
===== Boolean Values (Backwards Compatible)
191+
192+
[source,groovy]
193+
----
194+
static constraints = {
195+
internalNotes display: false // Never show this property
196+
title display: true // Show this property (default behavior)
197+
}
198+
----
199+
200+
===== DisplayType Enum Values
201+
202+
For more control over where properties are displayed, use the `DisplayType` enum:
203+
204+
[source,groovy]
205+
----
206+
import static grails.gorm.validation.DisplayType.*
207+
208+
class Book {
209+
String title
210+
String isbn
211+
Date dateCreated
212+
Date lastUpdated
213+
String internalNotes
214+
215+
static constraints = {
216+
dateCreated display: ALL // Override blacklist, show in all views
217+
lastUpdated display: OUTPUT_ONLY // Show only in show/index views
218+
isbn display: INPUT_ONLY // Show only in create/edit forms
219+
internalNotes display: NONE // Never show
220+
}
221+
}
222+
----
223+
224+
|===
225+
|DisplayType Value|Description
226+
227+
|`ALL`|Display the property in all views (input and output). This also overrides the default blacklist for properties like `dateCreated` and `lastUpdated`.
228+
|`NONE`|Never display the property in any view. Equivalent to `display: false`.
229+
|`INPUT_ONLY`|Display the property only in input views (create and edit forms).
230+
|`OUTPUT_ONLY`|Display the property only in output views (show and index/list views).
231+
|===
232+
233+
NOTE: Properties like `version`, `dateCreated`, and `lastUpdated` are excluded from input forms by default. Using `display: ALL` or `display: INPUT_ONLY` on these properties will override this blacklist and include them in input forms.
234+
186235

187236
=== Programmatic access
188237

0 commit comments

Comments
 (0)