Nice idea. But why put it in a comment?

script = ''
for table in db:
    for field in table:
        if field.required:
            script += 'jQuery("#%s_%s").attr("required","")' % (
field._tablename,field.name)

You can then cache the script and place in the layout.

Massimo



On Saturday, 24 August 2013 17:37:48 UTC-5, mr.freeze wrote:
>
> I want to take advantage of bootstrap's form validation classes so I need 
> to add a class to the field. Too bad there's not a hook into when a Field's 
> widget is rendered so you can manipulate it. Would you take a patch for 
> that?  I can work around it with your method in the meantime:
> for t in db.tables:
>     for f in db[t].fields:
>         if db[t][f].required:
>             db[t][f].comment = SCRIPT(
> 'jQuery("#%s_%s").attr("required","")' % (t,f))
>
>
> On Saturday, August 24, 2013 4:29:47 PM UTC-5, Massimo Di Pierro wrote:
>>
>> You could use something like:
>>
>>     db.table.field.comment = 'required'
>>
>> or 
>>
>> for field in db.table:
>>    if field.required:
>>        field.comment='required'
>>
>>
>> On Saturday, 24 August 2013 09:36:16 UTC-5, mr.freeze wrote:
>>>
>>> I want to show users which fields are required *before* they submit a 
>>> form. Before I reinvent the wheel, is there a mechanism for adding a 
>>> "required" class to fields that have IS_NOT_EMPTY or required=True already 
>>> built into web2py?
>>>
>>> Thanks,
>>> Nathan
>>>
>>

-- 

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

Reply via email to