Enter a string with a length shorter than 3 when prompted. You should get Sorry, your reply was invalid: value is too short. Min length is 3. Nothing surprising so far.
Now enter a string that consists of more than 20 characters. You'll see that it passes the validation.
Expected behavior: A string with more than 20 characters shouldn't satisfy the conditions to be a valid answer.
qCityName := survey.Question{
Name: "cityname",
Prompt: &survey.Input{
Message: "Enter a city name",
},
Validate: func(ans interface{}) error {
str, _ := ans.(string)
if len(str) > 20 {
return errors.New("Max length is 20")
}
return nil
},
}
var cityName string
survey.Ask([]*survey.Question{&qCityName}, &cityName, survey.WithValidator(survey.MinLength(3)))
This PR introduces a new change that rolls back the validation flow to the beginning as soon as we encounter a validation error. The current code is taking it from where it left off, ignoring the previous validators.
Steps to reproduce:
Sorry, your reply was invalid: value is too short. Min length is 3
. Nothing surprising so far.Expected behavior: A string with more than 20 characters shouldn't satisfy the conditions to be a valid answer.
This PR introduces a new change that rolls back the validation flow to the beginning as soon as we encounter a validation error. The current code is taking it from where it left off, ignoring the previous validators.