Thank You Massimo, it's enaugh for me - indeed, the code is rather simple.
Regards and good luck :)
brushek
W dniu wtorek, 7 stycznia 2014 09:09:04 UTC+1 użytkownik Massimo Di Pierro
napisał:
>
> This is the source for SQLFORM.dictform:
>
> def dictform(dictionary, **kwargs):
> fields = []
> for key, value in sorted(dictionary.items()):
> t, requires = SQLFORM.AUTOTYPES.get(type(value), (None, None))
> if t:
> fields.append(Field(key, t, requires=requires,
> default=value))
> return SQLFORM.factory(*fields, **kwargs)
>
> As you can see it is just a SQLFORM.factory except that it makes a guess
> for field types and requires. If you want to change those defaults, than
> you do not need this function at all. Perhaps it can be used as an example
> of how to do what you need to do.
>
>
>
> On Sunday, 5 January 2014 10:48:08 UTC-6, brushek wrote:
>>
>> Thank You Masimo for answer,
>>
>> Hm... so this is huge problem for me, because I have in dict many other
>> options (I showed only one field to show the problem). Is there any easy
>> way to append or insert Field (with corect select option generated in the
>> view) to the form created by SQLFORM.dictform ? Or, to change the
>> SQLFORM.dictform to SQLFORM.factory, but factory need to take dict with
>> (many) fields ? I was very happy to see dictform - it perfectly fit into
>> the config setter/updater for me, last thing I needed is to make select for
>> some of the fields :(.
>>
>> Regards
>> brushek
>>
>>
>>
>>
>> W dniu niedziela, 5 stycznia 2014 17:07:09 UTC+1 użytkownik Massimo Di
>> Pierro napisał:
>>>
>>> Unfortunately dictform does not support this. You can do:
>>>
>>> session.config = dict(NAME = 'a')
>>> form =
>>> SQLFORM.factory(Field('NAME',default=session.config['NAME'],requires=IS_IN_SET(('a','b','c','d','e'),
>>>
>>> error_message="Choose between a and e")))
>>> if form.process().accepted:
>>> session.config['NAME'] = form.vars['NAME']
>>>
>>>
>>>
>>> On Saturday, 4 January 2014 11:26:10 UTC-6, brushek wrote:
>>>>
>>>> Hello :)
>>>>
>>>> I have following code in controller:
>>>>
>>>> session.config = dict(NAME = 'a')
>>>> form = SQLFORM.dictform(session.config)
>>>> form.custom.widget.NAME['requires'] = IS_IN_SET(('a','b','c','d','e'),
>>>> error_message="Choose between a and e")
>>>> if form.process().accepted:
>>>> session.config.update(form.vars)
>>>>
>>>> validator is working OK, but I would like to change the type of NAME
>>>> field in form to select dropdown, instead simple input. How to do this ?
>>>> How to change the type of field after it is created by any SQLFORM(.*) ?
>>>>
>>>> Regards
>>>> brushek
>>>>
>>>
--
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.