I had to remove the use of show_if and instead implement custom JS to 
show/hide fields based on the boolean field.  With onvalidation function 
being used to preform validation.

Not sure that the show_if feature is properly implemented with regard to 
the validation system.  

Regards,
James
On Friday, December 4, 2020 at 11:26:40 PM UTC+10 James O' Driscoll wrote:

> Hey mate,
>
> I got around that specific validator,  however the is_in_set validator 
> causes the problem. (It’s needed to create the select field in HTML) 
>
> I managed to get around it with onvalidation, doing the validation based 
> on a state of the control but this is adding more logic on the backend and 
> takes away from the model functionality.  
>
> Regards,
> James
>
> On Fri, 4 Dec 2020 at 10:57 pm, Leonel Câmara <[email protected]> wrote:
>
>> You can change the field requires in the controller depending on whether 
>> the field should be shown doing something like this
>>
>> def index(): 
>>     db.purchase.coupon_code.show_if = (db.purchase.have_coupon==True) 
>>     if request.vars.have_coupon:
>>         db.purchase.coupon_code.requires = IS_NOT_EMPTY()
>>     else:
>>          db.purchase.coupon_code.requires = IS_EMPTY()
>>     form = SQLFORM(db.purchase).process() 
>>     return dict(form = form)
>>
>> db.purchase.coupon_code.show_if = (db.purchase.have_coupon==True)  
>>
>>
>>
>> A quinta-feira, 3 de dezembro de 2020 à(s) 07:05:55 UTC, 
>> [email protected] escreveu:
>>
>>> All,
>>>
>>> I am trying to get a solution to the above problem, I am using a 
>>> onvalidation function.  If have_coupon is checked then I call IS_NOT_EMPTY 
>>> and set the form.errors.coupon_code manually.  This is not ideal but it 
>>> works.
>>>
>>> However I cannot seem to get a work around for a dropdown input i.e. 
>>> IS_IN_SET as this is needed on the model to create the correct input but 
>>> inturn fails the processing of the form as onvalidation doesnot get called.
>>>
>>> Any help would be great.
>>>
>>> Regards,
>>> James
>>>
>>>
>>> On Wednesday, December 2, 2020 at 12:35:15 PM UTC+10 James O' Driscoll 
>>> wrote:
>>>
>>>> Hello all,
>>>>
>>>> I have a question regarding conditional fields and using validators.
>>>>
>>>> Take the example from the book with a slight change:
>>>>
>>>> db.define_table('purchase', Field('have_coupon', 'boolean'), 
>>>> Field('coupon_code', requires=IS_NOT_EMPTY()))
>>>>
>>>> with controller:
>>>>
>>>> def index(): 
>>>>     db.purchase.coupon_code.show_if = (db.purchase.have_coupon==True) 
>>>>     form = SQLFORM(db.purchase).process() 
>>>>     return dict(form = form)
>>>>
>>>> show_if works well but if i need validators in place for when say 
>>>> have_coupon is true, to validate coupon_code I get an error when 
>>>> have_coupon is false as coupon_code is empty.  
>>>>
>>>> I would prefer to keep the validator on the model, is there a way to 
>>>> accomplish this.
>>>>
>>>> Regards,
>>>> James
>>>>
>>>> -- 
>> Resources:
>> - http://web2py.com
>> - http://web2py.com/book (Documentation)
>> - http://github.com/web2py/web2py (Source code)
>> - https://code.google.com/p/web2py/issues/list (Report Issues)
>> --- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "web2py-users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/web2py/fiHjfVb01Z8/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> [email protected].
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/2ddf8a1a-2ebe-4ef9-a0e9-6fd5f6c2c26an%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/web2py/2ddf8a1a-2ebe-4ef9-a0e9-6fd5f6c2c26an%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/800a443a-a01c-47d3-8b92-6024d3c0086fn%40googlegroups.com.

Reply via email to