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 ?

0
3 comments

Such validations are not supported in the ModuleBuilder out of the box, but you can manually install and invoke the validator on the field:

val vi = ValidationInfo("Message", component)
val cv = ComponentValidator(this)
cv.installOn(component)
cv.updateInfo(vi)
0

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 ?

 

0

I'd suggest you review the ModuleWizardStep, ModuleBuilder, and the other wizard related classes in projectWizard package.

 

0

Please sign in to leave a comment.