Cies
06/11/2024, 2:55 PMFormDto
. The library sets a standard for the names (the name
attribute on HTML form fields) so they can be used to provide a structure to the data.Anders Sveen
06/11/2024, 8:13 PMCies
06/11/2024, 8:33 PMCies
06/11/2024, 8:34 PMCies
06/11/2024, 8:34 PMCies
06/11/2024, 8:35 PMCies
06/11/2024, 8:35 PMCies
06/11/2024, 8:36 PMname =
toNameString(ShowTicketsFormDto::ticketGroups, index, TicketGroupDto::id)
`Cies
06/11/2024, 8:37 PM*FormDto
data classes have the validate()
method on them, decaratively implemented with Konform. If we need more than one way to validate its very easy to just make more and abstract common bits.Cies
06/11/2024, 8:38 PMCies
06/11/2024, 8:39 PMCies
06/11/2024, 8:40 PMAnders Sveen
06/11/2024, 9:41 PMCies
06/12/2024, 8:08 AMselect
becomes a validatedSelect
which we pass the Konform ValidationResult
Anders Sveen
06/12/2024, 8:09 AMCies
06/12/2024, 8:09 AMCies
06/12/2024, 8:10 AMCies
06/12/2024, 8:11 AMCies
06/12/2024, 8:11 AMAnders Sveen
06/12/2024, 8:12 AMfun LABEL.inputWithConstraints(
path: String,
existingValue: String?,
inputType: InputType,
property: KProperty1<Any, String>
) {
input(inputType) {
name = path
value = existingValue ?: ""
property.javaAnnotations().forEach {
when (it) {
is Size -> {
minLength = it.min.toString()
maxLength = it.max.toString()
}
is Max -> max = it.value.toString()
is NotNull -> required = true
is NotEmpty -> required = true
else -> if (property.isRequired()) required = true // Should we do this? Maybe just rely on the annotations? Maybe fail fast?
}
}
}
}
(the javaAnnotations() extension method is custom helper))Anders Sveen
06/12/2024, 8:13 AMAnders Sveen
06/12/2024, 8:15 AMCies
06/12/2024, 8:17 AM