Description of the limitation and why it is relevant to address
As a developer I want to set the allowed length of a text in a textfield (single value or maximum / minimum length) so that it is possible to control the input and prevent wrong input. In our case we would like to allow only one single character A-Z.
Characters could be provided as regex string or list.
I think this is relevant for the VIKTOR platform because …
Submitter proposed design (optional)
vkt.TextField(‘Enter one character’, maximum_length=1, minimum_length=1, allowed=”A-Z”)
Current workarounds
None
Interesting case!
Just an idea for a workaround for now: you can of course have some explanatory (static) text telling the user what to do, and just like any other field the static text field can also be toggled visible or not visible. In other words, you could have a textfield with a message like “WARNING: only single character values allowed” pop up through a callback function that checks the value in the field where the character goes.
Would something like that already suffice?
def check_length_textfield(params, **kwargs):
if params.single_char:
if len(params.single_char) > 1:
return True
return False
class Parametrization(vkt.Parametrization):
single_char = vkt.TextField("Single char")
field_check_warning = vkt.Text("**⚠️ WARNING:** only single character entry allowed", visible=check_length_textfield)
Otherwise if you use a stepwise editor you can alway validate length on_next, and besides that there is of course the errors and validation options (but I don’t think that’s what you are looking for because that of course needs to be triggered, whereas the static field immediately shows)
Thank you @rweigand I have implemented a solution like your proposal for a workaround with an error.
1 Like