Which tool versions are you using?
SDK: v14.21.0
Platform: v25.06.4
Python: v3.11
Isolation mode: venv
Current Behavior
I’m trying to show the user a warning, which shouldn’t forbid continuing the following steps.
Violations work as intended, but UserMessage.warning
(/.info
/.success
) aren’t working. The message only appears in the terminal (when in dev mode), and not at all in the publication state.
Here’s a shortened version of what I’m attempting to do:
import viktor as vkt
def check_step1(params, **kwargs):
"""Warn if the toggle is On"""
violations = []
if params.step1.bool:
msg = "Toggle shouldn't be On"
# Record the violation
if True: # no impact on the user messages
violation = vkt.InputViolation(msg, fields=["step1.bool"])
print(msg)
violations.append(violation)
# User messages - NOT WORKING
vkt.UserMessage.info(f"INFO: {msg}")
vkt.UserMessage.warning(f"WARNING: {msg}")
vkt.UserMessage.success(f"SUCCESS: {msg}")
# Show the violations
if violations:
msgs = ". ".join([f"{v.message}. Fields: {v.fields}" for v in violations])
raise vkt.UserError(f"ERROR! {msgs}", input_violations=violations)
class Parametrization(vkt.Parametrization):
step1 = vkt.Step("Step1", on_next=check_step1)
step1.bool = vkt.BooleanField("Toggle", default=False)
step2 = vkt.Step("Step2")
step2.txt = vkt.Text("Welcome to step 2")
class Controller(vkt.Controller):
parametrization = Parametrization
Context
I want to use user messages because I have a case where a value x
should be smaller than x_warn
, and must be smaller than x_max
(both bounds depend on multiple parameters and are calculated on_next
). I therefore want to warn the user if they input x
> x_warn
, and forbid them from inputting x
> x_max
.