form.custom.begin doesn't add the form _class and other attributes

71 views
Skip to first unread message

Leonel Câmara

unread,
Mar 20, 2014, 12:14:57 PM3/20/14
to
{{form['_class'] = 'service-form'}}
{{form['_role'] = 'form''}}
{{=form.custom.begin}}


The generated html was:
<form action="#" enctype="multipart/form-data" method="post">

Is this the supposed behavior or am I doing something wrong?

The way I see it the output should be: 
<form action="#" enctype="multipart/form-data" method="post" class="service-form" role="form">

Any tips?

André Kablu

unread,
Mar 20, 2014, 2:17:30 PM3/20/14
to web...@googlegroups.com
you can do it by using

FORM(_class='yourclass', _role='role')

Leonel Câmara

unread,
Mar 20, 2014, 2:52:41 PM3/20/14
to web...@googlegroups.com
Yeah, I know I can do that. However, I actually think that, if this really doesn't work, then it is a bug; as there is no way to add a class or other attributes to the form HTML element in custom forms, which are supposed to be "custom".

Anthony

unread,
Mar 20, 2014, 3:16:23 PM3/20/14
to web...@googlegroups.com
It's not a bug, but it is a limitation. form.custom.begin is not an HTML helper (can't be because it's just the opening tag of the form), so it cannot be manipulated the same way you can manipulate other helper objects. In any case, if you're building a custom form (and for some reason cannot specify the class of the form at the time the form is created), it's just about as easy to manually write the HTML in place of form.custom.begin.

Anthony


On Thursday, March 20, 2014 2:52:41 PM UTC-4, Leonel Câmara wrote:
Message has been deleted

Leonel Câmara

unread,
Mar 21, 2014, 7:06:04 AM3/21/14
to web...@googlegroups.com
> it's just about as easy to manually write the HTML in place of form.custom.begin.

Why have form.custom.begin then? I thought the point was to abstract away whatever SQLFORM needs in the form declaration. So either form.custom.begin (and end) should be removed or this is a bug/serious limitation.  
  
If the DIV helper didn't let you add a class attribute would you call it a bug or a limitation?

Anthony

unread,
Mar 21, 2014, 5:07:17 PM3/21/14
to web...@googlegroups.com
If you couldn't add a class to a div, it would only be a bug if the class was defined to allow classes to be added. Otherwise, it's a limitation.

form.custom.begin is still useful even though it isn't easily manipulated, so I don't think it should be removed. And there are at least a few trivially easy alternatives, so I also don't think it is a "serious" limitation (it would be more serious in the case of DIV).

Anyway, feel free to submit a pull request if this functionality is important to you.

Anthony

unread,
Mar 21, 2014, 5:07:30 PM3/21/14
to web...@googlegroups.com

Leonel Câmara

unread,
Mar 24, 2014, 1:16:48 PM3/24/14
to web...@googlegroups.com
> Anyway, feel free to submit a pull request if this functionality is important to you.

Put my time where my mouth is? Eheheh, I should have expected this. I guess I'll try to find time to make it soon, as this issue annoys me, not sure if it's important, but I don't want to have to remember that form.custom.begin loses form attributes each time I use it.
Reply all
Reply to author
Forward
0 new messages