Textbox
Validation
The validator attribute is used with validate_textbox(string, validator) to determine if the current string is valid. It can be a Regex that needs to match the complete string, or a Function taking a String as input and returning a Bool. If the validator is a type T (for example Float64), validation will be tryparse(T, string). The textbox will not allow submitting the currently entered value if the validator doesn’t pass.
using CairoMakie
f = Figure()
tb = Textbox(f[2, 1], placeholder = "Enter a frequency",
validator = Float64, tellwidth = false)
frequency = Observable(1.0)
on(tb.stored_string) do s
frequency[] = parse(Float64, s)
end
xs = 0:0.01:10
sinecurve = @lift(sin.($frequency .* xs))
lines(f[1, 1], xs, sinecurve)
f
Attributes
bordercolor_focused_invalid
Defaults to RGBf(1, 0, 0)
Color of the box border when focused and invalid.
placeholder
Defaults to "Click to edit..."
A placeholder text that is displayed when the saved string is nothing.
reset_on_defocus
Defaults to false
Controls if the displayed text is reset to the stored text when defocusing the textbox without submitting.
restriction
Defaults to nothing
Restricts the allowed unicode input via is_allowed(char, restriction).
validator
Defaults to str->begin
true
end
Validator that is called with validate_textbox(string, validator) to determine if the current string is valid. Can by default be a RegEx that needs to match the complete string, or a function taking a string as input and returning a Bool. If the validator is a type T (for example Float64), validation will be tryparse(T, string).