Version 1 (modified by Serge Sunneach, 14 years ago) ( diff )


IS_ONE_OF_EMPTY() Validator

This one has all properties of IS_ONE_OF but one: it does not send back to the browser a potentially huge dropdown with all values.

Instead, it creates the INPUT box which can carry the corresponding lookup id.

And when the form gets sent back to the server, the content of this INPUT box gets validated on the server against the corresponding lookup table.

How to use the IS_ONE_OF_EMPTY?

In controller.

Keep in mind that the corresponding model assumes default validator against the organisation_id. The working example is controllers/

here the organisation_id is not mandatory, but if present, must be validated against the (large) organisation table.

def office():

    # the update forms are not ready. when they will - uncomment this and comment the next one
    #if request.args(0) in ('create','update'):
    if request.args(0) == 'create':
        db[table].organisation_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, ''))


Autocomplete - in the view.

And the complimentary view or/office_create.html

<script type="text/javascript">//<![CDATA[
$(function() {
    // Hide the real Input Field
    // Add a dummy field
    $("#or_office_organisation_id").after("<input id='dummy_organisation' class='ac_input' size=50 />");
    {{include 'or/organisation_autocomplete.js'}}
    // Populate the real Input when the Dummy is selected
    $("#dummy_organisation").result(function(event, data, formatted) {
        var newvalue =;
Note: See TracWiki for help on using the wiki.