This is my code
    form = SQLFORM.factory(
        Field('equipment_id',
              label=T('Equipment'),
              requires=IS_IN_SET({wo.equipment_id: db.equipment(wo.
equipment_id).name},
                                 zero=None),
        ),
        Field('sn',
              label=T('SN'),
              widget=lambda field, value: (
                SQLFORM.widgets.string.widget(field, value, _readonly=True
)),
        ),
        Field('code',
              label=T('WO'),
              requires=IS_EMPTY_OR(IS_IN_DB(db(query), 'wo.code', distinct=
True)),
        ),
        Field('client_id',
              label=T('Client'),
              requires=IS_IN_DB(db, 'client.id', '%(name)s', zero=T('Choose 
one...')),
        ),
        Field('manual_lang_id',
              label=T('Manual language'),
              requires=IS_IN_DB(db,
                                'manual_lang.id',
                                '%(name)s',
                                zero=T('Choose one...'),
              ),
        ),
        Field('co_code', default='', label=T('Customer order')),
        Field('so_code', default='', label=T('Supplier order')),
        Field('export', 'boolean', default=False, label=T('Export')),
        Field('notes', default='', label=T('Notes')),
        Field('observations', default='', label=T('Observations')),
        Field('est_finish',
              'date',
              label=T('Estimated finish'),
              notnull=True,
              required=True,
              requires=IS_DATE_IN_RANGE(  # format=T('%Y-%m-%d'),
                                        minimum=request.now.date() + 
timedelta(days=1),
                                        # maximum=request.now.date() + ,
                                        error_message=T('Must be a future 
date.')
              )
        ),
        *factory_fields,
    )


sábado, 30 de Março de 2019 às 19:03:40 UTC, Anthony escreveu:
>
> Hard to say without seeing your code, but it definitely works for me.
>
> On Saturday, March 30, 2019 at 2:37:27 PM UTC-4, João Matos wrote:
>>
>> How can I use the fields argument without a db?
>> I tried
>> fields=['sn']
>> but it returns an KeyError.
>>
>>
>> sábado, 30 de Março de 2019 às 18:27:11 UTC, Anthony escreveu:
>>>
>>> I don't see any advantage in using the fields parameter because the 
>>>> change I found
>>>> form.element('#no_table_sn')['_readonly'] = 'readonly' 
>>>> and the suggestion you made
>>>> widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _readonly=True)
>>>> only change 1 line, and using the fields would make me change all the 
>>>> Fields lines (if I'm not mistaken).
>>>>
>>>
>>> No, "fields" is an argument of SQLFORM:
>>>
>>> form = SQLFORM.factory(..., fields=['field1', 'field2', ...])
>>>
>>> Anyway, setting the _readonly attribute of the input widget and setting 
>>> writable=False in the Field() definition do two different things. The 
>>> former makes the input element read-only in the UI but is less secure 
>>> because it does not prevent writes on the server. The latter does not use 
>>> an input element to display the data in the UI, and it also prevents writes 
>>> on the server.
>>>
>>> Anthony
>>>
>>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to