Thanks Anthony.
The code you proposed gives an error on widget=SQLFORM.widgets.options.
widget: TypeError: append() takes no keyword arguments
I admit the user experience is odd, but you see, the "set" being empty is
the result of user activity, or lack thereof. This way the form submission
will always be impossible, and the error message will remind the users that
there is some configuration steps they should have completed elsewhere
before using this feature.
On Friday, May 12, 2017 at 9:15:42 PM UTC+2, Anthony wrote:
>
> It seems like you are aiming for an odd user experience -- in some cases
> you provide a select widget that has no options, and when the user submits
> the form, it returns an error saying the field cannot be empty -- yet there
> is no way to provide a value. What is the user supposed to do in that case?
>
> Anyway, you can do it this way:
>
> Field("value", type='string', label=field_name, default=value,
> requires=IS_IN_SET(set, multiple=(1, 2), error_message='Field
> cannot be empty'),
> widget=SQLFORM.widgets.options.widget)
>
> Setting multiple=(1, 2) indicates there must be at least one option
> selected but less than 2 (i.e., so, exactly 1). However, by specifying the
> "multiple" argument, the default widget would become the multi-select
> widget, so to get a standard select widget, you must also specify that via
> the "widget" argument.
>
> Anthony
>
> On Friday, May 12, 2017 at 2:43:00 AM UTC-4, Karoly Kantor wrote:
>>
>> I have a situation where the "set' in IS_IN_SET(set) is dynamic, and
>> sometimes will be empty in:
>>
>> form = SQLFORM.factory(
>> Field("value", type='string', label=field_name, default=value,
>> requires=IS_IN_SET(set)),
>> ... more fields ...
>> )
>>
>> I would expect that if 'set' is empty, this would always fail validation.
>> However, this one allows saving an empty value.
>>
>> How could I make it to always fail validation if the set is empty?
>>
>> I also tried this:
>>
>> requires= [IS_NOT_EMPTY(), IS_IN_SET(set) ]
>>
>> But this one brings up a simple text input field and accepts any text I
>> type.
>>
>> Thank you.
>>
>
--
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].
For more options, visit https://groups.google.com/d/optout.