Closed halshar closed 1 year ago
instead of type conversion i've switched to converting the input to int and checking, the below validator works without issues
func intValidtor(ans interface{}) error {
inpVal, _ := ans.(string)
if _, err := strconv.Atoi(inpVal); err != nil {
return errors.New("input must be an integer")
}
return nil
}
Hi, all user's inputs in a terminal are technically strings (even if they consists only of digits), and Survey will always store the result as a string, even if you applied a number validator to the result. Like you've discovered, it's the responsibility of your app to convert a Go string into another type that is more suitable for your purposes.
What operating system and terminal are you using? linux mint 20.2 uma, zsh
An example that showcases the bug.
What did you expect to see? the
ok
variable to be trueWhat did you see instead? the
ok
variable is falseinstead of ans.(int) i've tried all other integer types(signed and unsigned) but the value is still false negating the value works for integers but when I input any string the value becomes 0(default)
mod file: