Opened 9 years ago
Closed 9 years ago
#1963 closed enhancement (fixed)
Improve list handling callback javascript code
Reported by: | Nicklas Nordborg | Owned by: | Nicklas Nordborg |
---|---|---|---|
Priority: | minor | Milestone: | BASE 3.7 |
Component: | web | Version: | |
Keywords: | Cc: |
Description
While working with #1962 it became apparent that there are lots of very similar methods for handling callbacks after selecting a related item in an edit dialog. For example, after selecting a protocol for a sample:
samples.setProtocolCallback = function(event) { var frm = document.forms['sample']; var list = frm.protocol_id; if (list.length < 2 || list[1].value == 'NaN') { Forms.addListOption(list, 1, new Option()); } list[1].value = event.detail.id; list[1].text = event.detail.name; list.selectedIndex = 1; }
It should not be too difficult to create a generic callback that can replace more or less all existing implementations. Typically the only difference between the various functions are:
- The name of the form and input field, but we can get this with
event.currentTarget
. - If the option should be inserted at index=1 or index=0. This depends on if there is a 'none' option or not available.
- In some cases there is an additional call to a 'onclick' or 'onchange' method. It is better to implement this by sending a real 'onchange' event.
Change History (3)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.
(In [7001]) References #1963: Improve list handling callback javascript code
Added
Items.onItemSelected
callback handler that can be attached to 'base-selected' event. The handler will insert or update the list it is attached with the item information sent in the event. If the new information is different from the currently selected a 'change' event is firef.Most old event handlers should now be replaced with the new handler.