RudolfCardinal / pythonlib

Miscellaneous Python support functions
Apache License 2.0
11 stars 5 forks source link

Wrong displayed value when ValidateDangerousOperationNode is empty #3

Open martinburchell opened 4 years ago

martinburchell commented 4 years ago

https://github.com/RudolfCardinal/pythonlib/blob/master/cardinal_pythonlib/colander_utils.py#L495

If a ValidateDangerousOperationNode is left empty, the "required" validation for the child MandatoryStringNode fails before the parent node's validator() has a chance to be called. So the hidden target_value doesn't match the displayed value for the next form submission.

Any non-empty invalid value results in the ValidateDangerousOperationNode validator() being called and the displayed value being updated.

Example of this is on the delete user form for CamCOPS. If you leave the field empty and then enter the correct displayed value, the form fails validation.

@RudolfCardinal any thoughts on how to solve this? We can make the field non-mandatory but that doesn't seem quite right given that it is required. I see there is also something called deferred validation. I don't know if that would help.