That worked, thanks very much!

On Tuesday, July 2, 2019 at 4:21:33 PM UTC-4, Alessandro Molina wrote:
>
> How are you providing the "__field_validators__" value? 
> If you are using "__field_validators__" that expects the actual validator 
> instance, so the "__require_fields__" make no sense at that point because 
> you already provided "required=True" or no to the __init__ of the validator 
> set in "__field_validators__".
>
> I suspect you might want to use "__field_validator_types__" instead of 
> "__field_validators__", that should initialise the instance of the 
> validator itself and provide the "required=True" if the field is in 
> "__require_fields__"
>
> On Mon, Jul 1, 2019 at 11:37 PM Dax Mitchell <[email protected] 
> <javascript:>> wrote:
>
>> Hi, 
>>
>> We have a CrudRestControllerConfig and define our 
>> defaultCrudRestController with __form_options__.
>>
>> Suppose we have a field 'my_field' and it's included in the 
>> __form_options__'s __require_fields__ directive:
>>
>> ...
>> '__require_fields__': ['my_field'],
>> ...
>>
>>
>> Then if that field is left blank, TG2 will show an error and tell the 
>> user to 'Please enter a value'.
>>
>> However, we have defined a custom validator for that field that looks 
>> something like this:
>>
>> class MyValidator(FancyValidator):
>>
>>     def __init__(self, *args, **kw):
>>
>>         FancyValidator.__init__(self, *args, **kw)
>>
>>
>>     messages = dict(MyError=_('MyField Error'))
>>
>>
>>     def _validate_python(self, value, state):
>>
>>
>>         if value is None or not isinstance(value, str):
>>
>>             raise Invalid(self.message('MyError', state), value, state)
>>
>>
>>         if not is_my_value_valid(value):
>>
>>             raise Invalid(self.message('MyError', state), value, state)
>>
>>
>> If the field is left empty, the __require_fields__ mechanism doesn't seem 
>> to get invoked and the validator is not called either.  
>>
>> The empty value is accepted without issue. 
>>
>> Is this a known issue or am I doing something foolish?
>>
>> Many thanks
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "TurboGears" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/turbogears.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/turbogears/e2f2cf9a-4423-4575-ab8e-c7acff5a824e%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/turbogears/e2f2cf9a-4423-4575-ab8e-c7acff5a824e%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/turbogears.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/turbogears/97ab263b-4fcf-4f26-9bca-c22142041255%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to