Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-04-13 Thread João Matos
Had to revert to my old code form.element('#no_table_sn')['_readonly'] = 'readonly' instead of widget=lambda field, value: SQLFORM.widgets.string.widget(field, value), _readonly=True ), because otherwise after onvalidation web2py would remove "form-control " from th

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-30 Thread Anthony
Need to see the code that generated the KeyError, as well as the full traceback, and details about how/when the error was generated. On Saturday, March 30, 2019 at 3:31:41 PM UTC-4, João Matos wrote: > > This is my code > form = SQLFORM.factory( > Field('equipment_id', >

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-30 Thread João Matos
No, it doesn't. It simply doesn't show the field. sábado, 30 de Março de 2019 às 19:43:46 UTC, Jim S escreveu: > > Just change it to > > Field('sn', label=T('SN'), writable=False) > > Doesn't that work? > > > Jim > > > > > On Sat, Mar 30, 2019, 2:31 PM João Matos > > wrote: > >> This is my code

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-30 Thread Jim Steil
Just change it to Field('sn', label=T('SN'), writable=False) Doesn't that work? Jim On Sat, Mar 30, 2019, 2:31 PM João Matos wrote: > This is my code > form = SQLFORM.factory( > Field('equipment_id', > label=T('Equipment'), > requires=IS_IN_SET({wo.

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-30 Thread João Matos
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('S

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-30 Thread Anthony
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, An

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-30 Thread João Matos
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']

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-30 Thread Anthony
> > 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 wou

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-30 Thread João Matos
I used your widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _readonly=True) suggestion. 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.widget

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread Anthony
On Friday, March 29, 2019 at 5:42:10 PM UTC-4, João Matos wrote: > > Found a solution (more like a kludge) :) > > form.element('#no_table_sn')['_readonly'] = 'readonly' > I even tried adding > > _readonly='readonly' > > to the Field, but didn't work. > > Only works after the form exists. > Field

[web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread Anthony
On Friday, March 29, 2019 at 5:04:41 PM UTC-4, João Matos wrote: > > @Anthony > This is a SQLFORM.factory not a SQLFORM. > There is no database. > Are you sure fields parameter is applicable to SQLFORM.factory w/o a db? > Yes, it does work with SQLFORM.factory. > -- Resources: - http://web2py.c

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread João Matos
Found a solution (more like a kludge) :) form.element('#no_table_sn').attributes['_readonly'] = 'readonly' I even tried adding _readonly='readonly' to the Field, but didn't work. Only works after the form exists. Is there a better way? sexta-feira, 29 de Março de 2019 às 21:25:48 UTC, João

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread João Matos
The field I want to make read-only is sn. form = SQLFORM.factory( Field('equipment_id', label=T('Equipment'), requires=IS_IN_DB(db, 'equipment.id', '%(name)s', zero=None), ), Field('sn', 'integer', label=T('SN'), writable=False), Fiel

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread Jim Steil
Can you show some code? Mine is working fine without a db and specifying writable=False. -Jim On Fri, Mar 29, 2019 at 4:02 PM João Matos wrote: > It is readable and editable. > > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2p

[web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread João Matos
This is a SQLFORM.factory not a SQLFORM. There is no database. Are you sure fields parameter is applicable to SQLFORM.factory w/o a db? sexta-feira, 29 de Março de 2019 às 20:51:10 UTC, Anthony escreveu: > > By default, non-writable fields are excluded from create forms (though > shown in edit f

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread João Matos
It is readable and editable. -- 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 "w

[web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread Anthony
By default, non-writable fields are excluded from create forms (though shown in edit forms if readable=True). However, you can override that behavior by specifying the "fields" argument with a list of field names to include in the form. Anthony On Friday, March 29, 2019 at 4:32:27 PM UTC-4, Jo

Re: [web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread Jim Steil
Is readable set to True? -Jim On Fri, Mar 29, 2019 at 3:32 PM João Matos wrote: > Tried that, doesn't work. > With writable=False the field isn't shown. > > > sexta-feira, 29 de Março de 2019 às 20:12:45 UTC, Jim S escreveu: >> >> Set writable=False >> >> Field('end', 'date', requires=IS_DATE('

[web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread João Matos
Tried that, doesn't work. With writable=False the field isn't shown. sexta-feira, 29 de Março de 2019 às 20:12:45 UTC, Jim S escreveu: > > Set writable=False > > Field('end', 'date', requires=IS_DATE('%m/%d/%Y'), default=default_end, > writable=False) > > -Jim > > On Friday, March 29, 2019 at 2:

[web2py] Re: How to add a read-only field to a SQLFORM.factory

2019-03-29 Thread Jim S
Set writable=False Field('end', 'date', requires=IS_DATE('%m/%d/%Y'), default=default_end, writable=False) -Jim On Friday, March 29, 2019 at 2:39:58 PM UTC-5, João Matos wrote: > > Hello, > > How can I add a read-only field to a SQLFORM.factory? > > Thanks, > > JM > > -- Resources: - http://w