Skip to content

Disable invalid value for a setting #1284

Answered by kmvanbrunt
pihentagy asked this question in Q&A
Discussion options

You must be logged in to vote

To validate a Settable's value, use val_type and not onchange_cb.

val_type is a function which runs when setting the value. Whereas onchage_cb, as you've already noticed , runs after the Settable has been set to the new value.

Here is val_type's docsctring.

:param val_type: callable used to cast the string value from the command line into its proper type and
                 even validate its value. Setting this to bool provides tab completion for true/false and
                 validation using to_bool(). The val_type function should raise an exception if it fails.
                 This exception will be caught and printed by Cmd.do_set().

So in your case, instead of setting val_type to s…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by pihentagy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants