Sorry if I'm not explaining this well. The default widget for a list:string 
field is a vertically stacked list of inputs, one per value. There is a 
little + at right that allows me to add more inputs to the list 
dynamically. 

In a SQLFORM, when I set keepvalues=True the values are preserved in the 
form fields after form submission. But only one of the inputs from the 
list:string widget is left, holding just the last string value submitted 
for that field. In other words, the form doesn't remember the additional 
inputs I added to the widget (by clicking +) before submission, and it 
forgets the submitted values from those additional inputs as well.

I've experienced this on many forms, so I don't think it's my code. In the 
case that brought this up for me again, I'm creating a SQLFORM.factory with 
the fields defined in the controller. (You can see that I've got some for 
loops to simplify the creation and processing of a large number of fields, 
but otherwise it's straightforward.) The problem appears with the widgets 
for any of the list:string fields:

            
        message = ''
        output = ''

        flds = [Field('label_template', 'string'),
                Field('words', 'list:string'),
                Field('aligned', 'boolean'),
                Field('avoid', 'list:string'),
                Field('testing', 'boolean')]


        for n in ['one', 'two', 'three', 'four', 'five']:
            fbs = [Field('{}_prompt_template'.format(n), 'list:string'),
                   Field('{}_response_template'.format(n), 'list:string'),
                   Field('{}_readable_template'.format(n), 'list:string'),
                   Field('{}_tags'.format(n), 'list:reference tags',
                         requires=IS_IN_DB(db, 'tags.id', '%(tag)s',
                                           multiple=True)),
                   Field('{}_tags_secondary'.format(n), 'list:reference 
tags',
                         requires=IS_IN_DB(db, 'tags.id', '%(tag)s',
                                           multiple=True)),
                   Field('{}_tags_ahead'.format(n), 'list:reference tags',
                         requires=IS_IN_DB(db, 'tags.id', '%(tag)s',
                                           multiple=True)),
                   Field('{}_npcs'.format(n), 'list:reference npcs',
                         requires=IS_IN_DB(db, 'npcs.id', '%(name)s',
                                           multiple=True)),
                   Field('{}_locations'.format(n), 'list:reference 
locations',
                         requires=IS_IN_DB(db, 'locations.id',
                                           '%(map_location)s',
                                           multiple=True)),
                   Field('{}_instructions'.format(n),
                         'list:reference step_instructions',
                         requires=IS_IN_DB(db, 'step_instructions.id',
                                           '%(instruction_label)s',
                                           multiple=True)),
                   Field('{}_hints'.format(n), 'list:reference step_hints',
                         requires=IS_IN_DB(db, 'step_hints.id',
                                           '%(hint_label)s',
                                           multiple=True)),
                   Field('{}_step_type'.format(n), 'list:reference 
step_types',
                         requires=IS_IN_DB(db, 'step_types.id',
                                           '%(step_type)s',
                                           multiple=True)),
                   Field('{}_image_template'.format(n), 'string')]
            flds.extend(fbs)
        form = SQLFORM.factory(*flds)


        if form.process(keepvalues=True).accepted:
            vv = request.vars
            stepsdata = []
            for n in ['one', 'two', 'three', 'four', 'five']:
                nkeys = [k for k in vv.keys() if re.match('{}.*'.format(n), 
k)]
                filledfields = [k for k in nkeys if vv[k] not in ['', None]]
                if filledfields:
                    ndict = {k: vv[k] for k in nkeys}
                    stepsdata.append(ndict)
            if isinstance(vv['words'], list):
                wordlists = [w.split('|') for w in vv['words']]
            else:
                wordlists = [vv['words'].split('|')]
            paths = self.make_path(wordlists,
                                   label_template=vv.label_template,
                                   stepsdata=stepsdata,
                                   testing=vv.testing,
                                   avoid=vv.avoid,
                                   aligned=vv.aligned
                                   )
            message, output = self.make_output(paths)


        elif form.errors:
            message = BEAUTIFY(form.errors)








On Wednesday, August 12, 2015 at 11:04:46 AM UTC-4, Richard wrote:
>
> Could you show your model and controller...
>
> This make no sens...
>
> Richard
>
> On Wed, Aug 12, 2015 at 10:45 AM, Ian W. Scott <scot...@gmail.com 
> <javascript:>> wrote:
>
>> I never got any suggestions on this, even though it seems like a 
>> significant limitation of the widget. Has anyone come up with a solution 
>> for keeping all the values in a list:string field after form submission?
>>
>> Thanks.
>>
>>
>> On Wednesday, June 25, 2014 at 11:33:26 AM UTC-4, Ian W. Scott wrote:
>>>
>>> I've got a SQLFORM.factory form set to keep values after processing with 
>>> process(keepvalues=True). But it doesn't work on a list:string field. The 
>>> (otherwise very nice) widget loses all but the first value when the form is 
>>> submitted (i.e., all but the first text inputs for the field disappear). Is 
>>> there any way to carry those other text inputs and their values over?
>>>
>>>
>>> -- 
>> 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+un...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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