DeveloperGuidelinesTips ---- == (PROPOSAL. Remove this line if [https://code.launchpad.net/~sunneach/sahana/cleanIE/+merge/20171 merged]) == [http://bazaar.launchpad.net/%7Esunneach/sahana/cleanIE/files/628 This branch] has the proven working minimized-coding approach. It has an additional 'module' [http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/head%3A/views/auto_input.js views/auto_input.js] which contains all the repeating steps, and the actual views call it. === Step 1. The Controller === Use [wiki:IS_ONE_OF_EMPTY IS_ONE_OF_EMPTY] to prevent downloading the whole lookup table. === Step 2. The View === '''Auto_completed edit control''' This [http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/628/views/or/office_create.html 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 [[http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/head%3A/views/or/contact_create.html 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 [http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/head%3A/views/layout_popup.html TB_Refresh] calls the `set_parent_id` and `clean_up` if they exist in a view. This [http://bazaar.launchpad.net/~sunneach/sahana/cleanIE/annotate/head%3A/views/or/contact_create.html 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. ---- DeveloperGuidelinesTips