(PROPOSAL. Remove this line if merged)

This branch has the proven working minimized-coding approach. It has an additional 'module' views/auto_input.js which contains all the repeating steps, and the actual views call it.

Step 1. The Controller

Use IS_ONE_OF_EMPTY to prevent downloading the whole lookup table.

Step 2. The View

Auto_completed edit control

This view has the auto-completion enabled edit control which gets its {id, name} pairs from the /or/organisation:

{{entity_id = "or_office_organisation_id"}}
{{urlpath_c = "or"}}
{{urlpath_f = "organisation"}}
{{urlvar_field = "name"}}
{{include 'auto_input.js'}}

Auto_completed Person edit control

The person needs special treatment, that is why the flag is set: is_person=True:

{{entity_id = "or_contact_person_id"}}
{{is_person = True}}
{{include 'auto_input.js'}}

Auto_completed edit control with post-processing

If you need to update your view after the auto-completed field is changed, use the post_process "callback". Put into that any JS statement which works. For example, in the views/or/contact_create.html it is used to update the office list given the organisation via the load_offices call:

{{entity_id = "or_contact_organisation_id"}}
{{urlpath_c = "or"}}
{{urlpath_f = "organisation"}}
{{urlvar_field = "name"}}
{{post_process = "load_offices(false);"}}
{{include 'auto_input.js'}}

Dummy selector

The offices list is depending on organisation. The flag dummy_select makes it the empty dropdown with the single item default_value, waiting to be populated by load_offices. Other parameters are not used.

 {{entity_id = "or_contact_office_id"}}
 {{dummy_select = True}}
 {{default_value = T('Select an Organisation to see a list of offices')}}
 {{include 'auto_input.js'}}

The default_value works for the edit control as well.

Appendix: Pop-ups

The TB_Refresh calls the set_parent_id and clean_up if they exist in a view.

This set_parent_id uses it to pass the 'organisation_id' to the new office creation form.

And the clean-up in that same view is used to populate the offices dropdown after the new organisation or new office record get created.


Last modified 11 years ago Last modified on 03/01/10 07:27:30
Note: See TracWiki for help on using the wiki.