Again, you can't use SQLFORM.factory just to insert a single input into a
form -- it creates a whole form of its own. If you want to make use of the
IS_IN_DB validator to build the options for a SELECT widget, you can do
something like:
SELECT([OPTION(v, _value=k) for k, v in
IS_IN_DB(db, 'mytable.id', '%(myfield)s').options()], _name=
'mytable')
But a better approach would probably be to simply create your entire form
via SQLFORM.factory, and then if you need a custom layout, use the
form.custom elements as described in the book.
Anthony
On Thursday, March 6, 2014 7:02:45 PM UTC-5, [email protected] wrote:
>
> Hi all, and thanks for your replies.
>
> I intent to use the sqlform.factory to create dropdown list from DB data
> as inputs for a form. Why.? Because i want to use predefine values store on
> DB as a list for dropdown.
> The form actually works as view, but only the 1st input value of the 1st
> dropdown list is passing to vars. Second is empty, despite the value i
> chose.
>
> Recently, i made another test. I created a dropdown list using
> sqlform.factory from DB data; later on the same form i made and input
> select dropdown list based on values i enter manually. The results are only
> the 1st value from the sqlform.factory is passing to vars, second input is
> empty.
>
>
>
> Thanks.
>
>
> On Thursday, March 6, 2014 12:13:06 PM UTC-5, Anthony wrote:
>>
>> SQLFORM.factory generates an entire HTML form, not just an individual
>> field. I suppose you could extract an individual input element from the
>> form (via the server side DOM), but you might as well just use the INPUT()
>> helper in that case. Why are you trying to use SQLFORM.factory there rather
>> than INPUT()?
>>
>> On Wednesday, March 5, 2014 11:38:34 AM UTC-5, [email protected] wrote:
>>>
>>> Anthony,
>>>
>>> It is just a form with 2 sqlform.factory based on DB dropdown lists. 1st
>>> values passes to form.vars, second do not.
>>>
>>> Is it possible to have many sqlform.factory based on DB dropdown lists
>>> on same form ??
>>>
>>>
>>>
>>> Thanks.!
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Wednesday, March 5, 2014 9:11:58 AM UTC-5, Anthony wrote:
>>>>
>>>> I don't think HTML allows nested forms.
>>>>
>>>> On Wednesday, March 5, 2014 1:29:57 AM UTC-5, [email protected] wrote:
>>>>>
>>>>> Hi all,
>>>>>
>>>>> I have a Nested SQLform.factory inside a custom fields form.
>>>>>
>>>>> My code:
>>>>>
>>>>> form = FORM(TABLE(TR("Numero de
>>>>> documento:",INPUT(_type="text",_name="noid",requires=IS_NOT_EMPTY()),requires=IS_NOT_IN_DB(db,
>>>>>
>>>>> 'tabla1.noid')),
>>>>> TR("Tipo de documento:" ,
>>>>> SQLFORM.factory(Field('tid', label='',
>>>>> requires=IS_IN_DB(db,'tabla2.tipoid',orderby=db.tabla2.tipoid)) , buttons
>>>>> =
>>>>> [''] ,requires=IS_NOT_EMPTY())),
>>>>>
>>>>> TR("Nombre:",INPUT(_type="text",_name="nombre",requires=IS_NOT_EMPTY())),
>>>>> TR("Seleccione Tipo RH:" ,
>>>>> SQLFORM.factory(Field('trh', label='',
>>>>> requires=IS_IN_DB(db,'tabla2.tiporh',orderby=db.tabla2.tiporh)) , buttons
>>>>> =
>>>>> [''] ,requires=IS_NOT_EMPTY())),
>>>>> TR("",INPUT(_type="submit",_value="Guardar"))))
>>>>>
>>>>> if form.accepts(request,session):
>>>>>
>>>>> db.tabla1.insert(noid=form.vars.noid,tid=form.vars.tid,nombre=form.vars.nombre,trh=form.vars.trh)
>>>>>
>>>>>
>>>>> Problem is, I only can get the 1st dropdown list option. Second i dont
>>>>> get it pass from form.vars.
>>>>>
>>>>>
>>>>> Can someone let me know what im doing wrong. Thnx.
>>>>>
>>>>
--
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/d/optout.