First, don't use Crud, as it has been deprecated. Just use SQLFORM.

To apply special formatting to required fields, you can either create 
custom widgets or create a custom formstyle function that generates the 
desired HTML markup.

A custom widget might look like this:

Field('name', widget=lambda f, v: SQLFORM.widgets.string.widget(f, v, _class
='required'))

Then add a CSS rule for the "required" class.

Creating a custom formstyle function is more complex. You can check out the 
framework code for an example:

https://github.com/web2py/web2py/blob/ad43249f6148402890077a0a649e46b42fa6a8ab/gluon/sqlhtml.py#L1033

Anthony

On Wednesday, April 12, 2017 at 2:27:35 AM UTC-4, [email protected] 
wrote:
>
> Suppose i create a table:
> db.define_table('device',
> Field('name',unique=True,notnull=True),
> Field('alias_name',requires=IS_NOT_EMPTY(error_message='field can not be 
> empty')),
> Field('devicetype'))
>
> and i am creating a form as:
> form = crud.create(db.testbed)
>
> From table definition it is clear that 'name' and 'alias_name' field can't 
> be empty but user can leave 'devicetype' field blank. So i want that when 
> form will be opened to user for entering the values, fields such as  'name' 
> and 'alias_name' should be highlighted with some special mark such as 
> star(*) so user get idea that he can't leave these fields blank.
> How to do that?
> thanks.
>
>
>

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

Reply via email to