简体   繁体   中英

web2py FORM customisation

Is it possible to use form.custom.### in my forms which are not created from SQLFORM class. For instance I want to make a custom form like so:

form = FORM(
            LABEL('Select a search option', _for='search_option'),
            SELECT(__name='search_option', _onchange="jQuery('props_ajaxholder').empty(); web2py_component(jQuery(this).val(), 'props_ajaxholder');", *[OPTION(search_options[so], _value=so.lower().strip() + '.load') for so in search_options]),
        _id='matchingForm',formstyle='table2cols')

In the view, i want to customise this, so that i can insert <div id='placehlder'></div> between the select and the submit button. The submit button is only shown once an option is selected.

You cannot use form.custom with FORM. If you want to use it, build your form with SQLFORM.factory instead.

If you need to use FORM, you can wrap DIV around elements when creating the FORM.

form = FORM(
            DIV(
                LABEL('Select a search option', _for='search_option'),
                SELECT(__name='search_option', _onchange="jQuery('props_ajaxholder').empty(); web2py_component(jQuery(this).val(), 'props_ajaxholder');", *[OPTION(search_options[so], _value=so.lower().strip() + '.load') for so in search_options]),
                INPUT(_type='submit',_value='Submit!', _class="hidden"),
                _id="placehlder"),
            _id='matchingForm',formstyle='table2cols')

Showing/hiding submit button can be easily done with jQuery/CSS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM