Validation on wrapped DialogPanel

The question is about validation (kotlin ui dsl 2)

If I do it in standard way, it works:

override fun createCenterPanel() = panel {
      
            if (name != null) {
                row {
                    label("Schema name:")
                    textField().validationOnApply {
                        if (it.text.trim().isEmpty()) {
                            error("Name is required")
                        } else null
                    }.bindText({ name ?: "" }, { name = it })
                        .also {
                            focusedComponent = it.component
                        }
                }.bottomGap(BottomGap.SMALL)
            }
            row {
                cell(editSchemaComponent.getComponent())
            }
        }
    }

But if I wrapped it using JBScrollPane, it doesn’t work

override fun createCenterPanel(): JComponent{
    p = panel {
        if (name != null) {
            row {
                label("Schema name:")
                textField().validationOnApply {
                    if (it.text.trim().isEmpty()) {
                        error("Name is required")
                    } else null
                }.bindText({ name ?: "" }, { name = it })
                .also {
                    focusedComponent = it.component
                }
            }.bottomGap(BottomGap.SMALL)
        }
        row {
            cell(editSchemaComponent.getComponent())
        }
    }

    return JBScrollPane(p).apply {
        preferredSize = Dimension(1000, 1000)
    }
}

How to make it work? It’s very convenient to organize code with Kotlin UI DSL, sometimes I use cell(panel), etc. But have no idea how to make validation

I had similar experience, the problem is that the component returned is not a DialogPanel so the DialogWrapper doesn’t know how to register the validators.

In my plugin I solved it adding this code in the createCenterPanel, not sure if it’s really good but at least works:

 dialogPanels.forEach { dialogPanel ->
            dialogPanel.registerValidators(myDisposable) { map: Map<JComponent, ValidationInfo> ->
                isOKActionEnabled = ContainerUtil.and(map.values) { info: ValidationInfo -> info.okEnabled }
            }
        }