Have you tried IS_EMPTY_OR(IS_IN_SET(...))?
See http://web2py.com/book/default/chapter/07#Validators
Anthony
On Friday, September 30, 2011 1:13:32 PM UTC-4, Jan Rozhon wrote:
>
> Hi all,
>
> as a newbie in web2py I have encountered a problem with my web2py
> application. I want one part of the form to be optional, but the form
> is created by the SQLFORM.factory and one of its optional fields is a
> dropdown list, which uses "requires=IS_IN_SET...", thus forcing a user
> to choose a value, which is not desired behavior.
> The optional part of the form is connected with the checkbox, when it
> is checked the part appears and when it is unchecked it hides (using
> jquery), therefore the user in some cases doesnt even see the field.
> Could you please give me a hint how to bypass the validation, or how
> to do the trick differently?
>
> In controller i have:
> def index():
> form = SQLFORM.factory(
> Field('uac', 'boolean', default=True),
> Field('server_ip', requires=IS_IPV4()),
> Field('local_ip_uac'),
> Field('uac_scenario',
> requires=IS_IN_SET(functions.list_dir('/mnt/jro/ng/pbx/
> scenarios'),zero='Choose one')),
>
> Field('uas', 'boolean', default=False),
> Field('local_ip_uas'),
> Field('uas_scenario',
> requires=IS_IN_SET(functions.list_dir('/mnt/jro/ng/pbx/
> scenarios'),zero='Choose one')),
> ....
>
> In view I have this jquery code:
> <script>
> jQuery(document).ready(function(){
> jQuery('#input_form_local_ip_uas__row').hide();
> jQuery('#input_form_uas_scenario__row').hide();
> jQuery('#input_form_uas').change(function(){
> if(jQuery('#input_form_uas').attr('checked')) {
> jQuery('#input_form_local_ip_uas__row').show();
> jQuery('#input_form_uas_scenario__row').show();}
> else {
> jQuery('#input_form_local_ip_uas__row').hide();
> jQuery('#input_form_uas_scenario__row').attr('disabled',
> 'disabled');}});
> });
> </script>