Changes between Initial Version and Version 1 of IS_ONE_OF_EMPTY


Ignore:
Timestamp:
02/03/10 19:02:42 (13 years ago)
Author:
Serge Sunneach
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • IS_ONE_OF_EMPTY

    v1 v1  
     1
     2== IS_ONE_OF_EMPTY() Validator ==
     3
     4This one has all properties of [wiki:IS_ONE_OF IS_ONE_OF] but one:
     5it '''does not''' send back to the browser a '''potentially huge''' dropdown with all values.[[BR]]
     6
     7Instead, it creates the INPUT box which can carry the corresponding lookup id.[[BR]]
     8
     9And 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.
     10
     11'''How to use the IS_ONE_OF_EMPTY?'''
     12
     13'''In controller.'''
     14
     15
     16Keep in mind that the corresponding model assumes ''default validator'' against the organisation_id.
     17The working example is [http://bazaar.launchpad.net/~flavour/sahana/sahanapy-trunk/annotate/569/controllers/or.py controllers/or.py]:[[BR]]
     18
     19here the organisation_id is not mandatory, but if present, must be validated against the (large) organisation table.
     20{{{
     21def office():
     22...
     23
     24    # the update forms are not ready. when they will - uncomment this and comment the next one
     25    #if request.args(0) in ('create','update'):
     26    if request.args(0) == 'create':
     27        db[table].organisation_id.requires = IS_NULL_OR(IS_ONE_OF_EMPTY(db, 'or_organisation.id'))
     28
     29...
     30}}}
     31
     32'''Autocomplete - in the view.'''
     33
     34And the complimentary view [http://bazaar.launchpad.net/~flavour/sahana/sahanapy-trunk/annotate/569/views/or/office_create.html or/office_create.html]
     35
     36{{{
     37<script type="text/javascript">//<![CDATA[
     38$(function() {
     39    // Hide the real Input Field
     40    $("#or_office_organisation_id").hide();
     41    // Add a dummy field
     42    $("#or_office_organisation_id").after("<input id='dummy_organisation' class='ac_input' size=50 />");
     43    {{include 'or/organisation_autocomplete.js'}}
     44    // Populate the real Input when the Dummy is selected
     45    $("#dummy_organisation").result(function(event, data, formatted) {
     46        var newvalue = data.id;
     47        $("#or_office_organisation_id").val(newvalue);
     48    });
     49});
     50//]]></script>
     51}}}