[The validator] can be a Regex that needs to match the complete string, or a Function taking a String as input and returning a Bool
So you can either use a regex like r"\d+(, \d+)*" or something to that effect, or you use a function that returns true only if your requirement is met, and that could be:
function validator_func(str)
parts = strip.(split(str, ","))
all(parts) do part
tryparse(Int, part) !== nothing
end
end
In fact I don’t know how to call the validator function on the Textbutton, i.e, how to call the function properly (do I have to use the validator argument ?). Sorry for the basic question, I’m starting with Julia.
Should I use
tb = Textbox(f[1, 1], placeholder = “Enter a string…”, validator = validator_func())
or
tb = Textbox(f[1, 1], placeholder = “Enter a string…”, validator = validator_func(string, validator))
or
…
using GLMakie
function validator_func(str)
parts = strip.(split(str, “,”))
all(parts) do part
tryparse(Int, part) !== nothing
end
end
f = Figure()
tb = Textbox(f[1, 1], placeholder = “Enter a string…”, validator = validator_func(string))
f
You pass the function itself, so that the Textbox can call it itself when it wants to check if the text is valid. So in this case simply validator = validator_func