I want a hidden input with a custom attribute (e.g.: data-geo) to be stored 
in the database upon form validation.

<input name="latitude" data-geo="lat" style="display:none">


How can I achieve this ?


   1. Adding raw html to a custom form, although custom forms have a lot of 
   drawbacks in web2py
   
   2. Messing with DOM. At your own risks.
   
   3. SQLFORM "hidden" attribute ? Well no. I cannot set the data-geo 
   attribute there.


SQLFORM allows us to add hidden fields to a form using a dict()-based 
syntax (cf. 
http://www.web2py.com/books/default/chapter/29/07/forms-and-validators#Hidden-fields
)
I think this is very minimalistic, as it only allows us to set a name and 
value to hidden inputs.


Shouldn't "hidden fields" be a list of fields instead of a dictionary ?

What if we could do something like this :

form = SQLFORM(db.table, hidden=[db.table[field] for field in ['this_one', 
'that_one']])

or even:

form = SQLFORM(db.table, hidden=['this_one', 'that_one'])

The result here would be pretty much the same as the previous syntax, but 
with the new syntax we could also do:

form = SQLFORM(db.table, hidden=[Field('latitude', widget=lambda k,v: 
SQLFORM.widgets.string.widget(k,v, **{'_data-geo':'lat'})])



But then... I guess going through the trouble of redefining a Field for the 
purpose of hiding it seems a bit tedious. DOM modification probably takes 
the same amount of time.

Perhaps giving a standard name to the <div> that holds hidden fields would 
help in that regard ?

Maybe something like : <div id="table_hidden_field">

But as far as I know, this <div> isn't always appended to a form (for 
instance FORM and SQLFORM.factory don't have it).


Any thought on the matter ?

-- 
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