" If the page contains a single form, you can set formname=None and
omit the hidden field in the view."
Source: http://www.web2py.com/book/default/chapter/07
Because if I do that (using formname=None and omit the hidden field in
the view), the form has errors and enter here as soon as I load it:
elif form.errors:
response.flash = 'form has errors'
But if I put a name in formname and also put the hidden field in the
view, it works without errors.
OK, I see it now.
Is there a way to change how the custom.widget serialize? For example:
{{=form.custom.widget.texto}}
Gets serialized into:
<input class="string" id="sugerencias_texto" name="texto" type="text"
value="" />
But I want a textarea like this:
<textarea name="texto" cols="35" rows="8" id="question_2434"
onKeyUp="counterUpdate('question_2434',
'countBody','8000');"></textarea>
(but also to keep the validation provided by web2py).
Can I do this?
I don't see how does it realiz that is a textarea instead of input
type="text" and where should I add this.
thank you. Where should I put this and what to put on the view?
I put it in the controller and I get a syntax error:
Traceback (most recent call last):
File "/home/sbassi/Downloads/web2py/gluon/restricted.py", line 176,
in restricted
ccode = compile2(code,layer)
File "/home/sbassi/Downloads/web2py/gluon/restricted.py", line 163,
in compile2
return compile(code.rstrip().replace('\r\n','\n')+'\n', layer, 'exec')
File "/home/sbassi/Downloads/web2py/applications/sug3/controllers/default.py",
line 13
db.sugerencias.texto.widget=lambda field,value:
SQLFORM.widgets.TextWidget.widget(field,value,cols="35" rows="8")
^
SyntaxError: invalid syntax
Here is the controller code:
def index():
form = SQLFORM(db.sugerencias)
db.sugerencias.texto.widget=lambda field,value:
SQLFORM.widgets.TextWidget.widget(field,value,cols="35" rows="8")
if form.accepts(request.vars, formname='indexform'):
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill the form'
return dict(form=form)
Thanks, its getting better!!!
Is this documented somewhere?
I found something strange, with this:
db.sugerencias.texto.widget=lambda
field,value:SQLFORM.widgets.text.widget(field,value,cols="35",rows="8")
form = SQLFORM(db.sugerencias)
I get this:
<textarea class="string" cols="40" id="sugerencias_texto" name="texto"
rows="10"></textarea>
But I was expecting this:
<textarea class="string" cols="35" id="sugerencias_texto" name="texto"
rows="8"></textarea>
Then I tried to add something else and I couldn't. I need to have it like this:
<textarea class="string" cols="35" id="sugerencias_texto" name="texto"
rows="8" onKeyUp="counterUpdate('question_2434',
'countBody','250');"></textarea>
To do this I tried:
db.sugerencias.texto.widget=lambda
field,value:SQLFORM.widgets.text.widget(field,value,cols="35",rows="8",onKeyUp="counterUpdate('question_2434',
'countBody','250');")
form = SQLFORM(db.sugerencias)
But it is ignored and I get:
<textarea class="string" cols="40" id="sugerencias_texto" name="texto"
rows="10"></textarea>
So there are 2 problems, first I get 40 and 10 when I put 35 and 8,
and the 2nd error is that the onKeyUp is ignored :(