How do I validate fields in ModuleWizardStep/ModuleBuilder like we do in DialogWrapper ?
Answered
I've been trying to make a wizard for creating a project using DialogWrapper until now, when I realised we can define a new ModuleBuilder.
So I started changing my code to work with ModuleBuilder. But it seems I'm unable to provide field level validations like in DialogWrapper.
In DialogWrapper we have a method to return ValidationInfo and the JTextField object to highlight the field
override fun doValidate(): ValidationInfo? {
if(!gitUrlField.text.matches(Regex("^https?://[a-zA-Z0-9.+_\\-/]+\\.git$"))){
return ValidationInfo("Invalid git url is specified", gitUrlField)
}
if(!File(projectLocationField.text).exists()){
return ValidationInfo("Specified folder doesn't exist. Please create the folder and try again", projectLocationField)
}
return null
}
How can we achieve the same in a custom ModuleWizardStep ?
Please sign in to leave a comment.
Such validations are not supported in the ModuleBuilder out of the box, but you can manually install and invoke the validator on the field:
1. How do I handle the processing steps, where I can maybe implement `Task.withResult` to show a progress bar while git clone or some other process happens in the background.
2. How do I disable the next button until all the given fields are valid, when I'm using `ValidationInfo` ?
3. How do I skip the last project folder selection dialog and provide the required data programatically ?
I'd suggest you review the ModuleWizardStep, ModuleBuilder, and the other wizard related classes in projectWizard package.