form.vars will include only fields defined in the form object (things you
do on the client will not affect the form object on the server). The extra
variables will be available in request.post_vars, so you could include
logic to check request.post_vars and add fields to SQLFORM.factory based on
the variables that have been submitted.
Anthony
On Monday, February 10, 2014 11:42:34 AM UTC-5, Andrey K wrote:
>
> Dear web2py users,
> I would like to add dynamically fields to SQLFORM.factory defined in the
> model in client side by jQuery and then get the added fields values back to
> db (by "if form.accepted") via the standard form submit ,embedded in
> SQLFORM.factory . It does not seems to work on the server side - I can't
> get my values via form.vars.X where UI shows me new fields .
> Any idea what is wrong? Is the any other/better way to do it? Any your
> advice would be very helpful.
>
> Here is my code:
> *default.py:*
> def test_view():
> fields=[Field('your_script', 'upload')]
> form =
> SQLFORM.factory(db.tool,*fields,table_name='tool_upload_tab').process()
> if form.accepted:
> response.flash = form.vars #! it does not bring me any new
> variables apart from the ones i have got from defatul.py
> return dict(form=form)
>
> *default\test_view.html*
> {{extend 'layout.html'}}
> {{=form}}
> <input type="button" value="Add Filed to Table" class="add" id="addTable"
> />
> <script type="text/javascript">
> $(document).ready(function() {
> $("#addTable").click(function(){
> var fieldWrapper = $('<tr
> id="tool_upload_tab_extrafield1__row"></tr>');
> var fName0 = $("<td><input type=\"text\"
> id=\"tool_upload_tab_field1_value\" class=\"fieldname\" /></td>");
> var fName1 = $("<tr><td><input type=\"text\"
> id=\"tool_upload_tab_field1_comment\" class=\"fieldname\" /></td></tr>");
> var fName2 = $("<td><input type=\"text\"
> id=\"tool_upload_tab_field1_label\" class=\"fieldname\" /></td>");
> fieldWrapper.append(fName0,fName1,fName2);
> $('tbody').append(fieldWrapper);
> });
> });
> </script>
>
>
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.