On Friday, July 1, 2016 at 10:47:22 AM UTC-7, ktesr...@gmail.com wrote:
>
> Anthony,
>
> can you share if you have any examples. how can I keep track of that index 
> as I am not finding any example to get count of request.vars
>
> vars: <Storage {'opt1': ['3', '3'], 'opt2': ['12 ', '18 '], 'opt3': ['1', 
> '9'], 'txt1': ['1', '15']}>
> in this case I have four vars coming from browser which I should insert to 
> database request.vars.opt1, request.vars.opt2, request.vars.opt3 and 
> request.vars.txt1
>
> when I iterate loop for first time I should insert 3,12,1,1 as one record 
> and 2nd time it should insert 3,18,9,15 and so on based on data entry form
>
> In the above case there are 2 records but sometimes it can be more than 2 
> like -> vars: <Storage {'opt1': ['3', '3','6'], 'opt2': ['12 ', '18 
> ','21'], 'opt3': ['1', '9','12'], 'txt1': ['1', '15','27']}>
>
>
>
Can you use len(request.vars["opt1"]) ?

/dps

 

> On Monday, June 6, 2016 at 9:06:10 AM UTC-6, Anthony wrote:
>
>> Looks like each set of inputs has the same input names, so you get back a 
>> list for each variable. I believe browsers preserve the order of input 
>> values for inputs with the same name, so you should be able to just run a 
>> loop and do a separate insert for each set of items in the lists (i.e., on 
>> the first loop, extract element [0] from each list, on the second loop, 
>> extract element [1], etc.).
>>
>> Anthony
>>
>> On Sunday, June 5, 2016 at 8:54:47 PM UTC-4, ktesr...@gmail.com wrote:
>>>
>>> I am getting request.vars as shown below when I print it
>>>
>>> vars: <Storage {'opt1': ['3', '3'], 'opt2': ['12 ', '18 '], 'opt3': 
>>> ['1', '1'], 'txt1': ['1', '1']}>
>>>
>>> these values are given as input from user interface and it has 2 rows, 
>>> each row has 3 dropdown and 1 text box
>>>
>>> now how do I read each item and insert into database, in the database 
>>> there is a table that has 4 columns, as per my requirement now it has to 
>>> insert 2 records in that table
>>>
>>> On Friday, June 3, 2016 at 2:21:48 PM UTC-6, Anthony wrote:
>>>
>>>> On Friday, June 3, 2016 at 12:35:49 PM UTC-4, ktesr...@gmail.com wrote:
>>>>>
>>>>> it is a single select, the values are populated from controller into a 
>>>>> view dynamically in jquery
>>>>>
>>>>
>>>> OK, so what's wrong with your current approach? What are you trying to 
>>>> achieve? Hard to help without seeing your code (e.g., model definitions, 
>>>> etc.). Also, why are you using .getlist for a variable that isn't a list, 
>>>> and then just extracting the first element (which you would get if not 
>>>> using .getlist)?
>>>>
>>>> Anthony
>>>>
>>>>
>>>>> On Friday, June 3, 2016 at 6:32:34 AM UTC-6, Anthony wrote:
>>>>>>
>>>>>> Hard to say because it's not clear (a) what kind of data are in opt1, 
>>>>>> opt2, etc. (are they multi-select widgets producing lists or just single 
>>>>>> selects?) and (b) how the form inputs map to your database fields.
>>>>>>
>>>>>> Anthony
>>>>>>
>>>>>> On Thursday, June 2, 2016 at 11:55:13 PM UTC-4, ktesr...@gmail.com 
>>>>>> wrote:
>>>>>>>
>>>>>>> Anthony
>>>>>>>
>>>>>>> I wanted to iterate all the values from request.vars these values 
>>>>>>> are passed using ajax function from View, in the View each row will 
>>>>>>> have 3 
>>>>>>> drop downs and 1 textbox to take input from user
>>>>>>> there can be minimum 1 row. I am passing all the control names thru 
>>>>>>> ajax function
>>>>>>>
>>>>>>> View
>>>>>>> =======
>>>>>>> <script>
>>>>>>> /* jquery that builds html form written here */
>>>>>>>
>>>>>>> ajax('{{=URL('insert_data')}}',['opt1','opt2','opt3','txtt1'],'target');
>>>>>>>  
>>>>>>> // opt1, opt2 and opt3 are dropdown control names and txt1 is the name 
>>>>>>> if 
>>>>>>> textbox control all are html controls dynamically crated using jquery
>>>>>>>
>>>>>>> </script>
>>>>>>> <div id=...></div>
>>>>>>> <div id='target'></div>
>>>>>>>
>>>>>>> Controller
>>>>>>> ==========
>>>>>>> def insert_timesheet():
>>>>>>>  
>>>>>>>  orglist = request.vars.getlist("opt1")
>>>>>>>  response.flash = str(orgval)
>>>>>>>
>>>>>>>  ##db.Table.insert(field1=opt1[0],.....)
>>>>>>>  return locals()
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Thursday, June 2, 2016 at 7:34:04 PM UTC-6, Anthony wrote:
>>>>>>>
>>>>>>>> Please show some code and explain exactly what you want to do. To 
>>>>>>>> get a particular value from request.vars, just do 
>>>>>>>> request.vars.name_of_variable.
>>>>>>>>
>>>>>>>> Anthony
>>>>>>>>
>>>>>>>> On Thursday, June 2, 2016 at 8:07:13 PM UTC-4, ktesr...@gmail.com 
>>>>>>>> wrote:
>>>>>>>>>
>>>>>>>>> I am getting selected values from View to Controller using 
>>>>>>>>> request.vars
>>>>>>>>>
>>>>>>>>> I can see the values are coming as key value pair but not able to 
>>>>>>>>> figure out how to read each value and insert them in DB
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>

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