",
vo_entry.name,
@@ -101,12 +101,14 @@ function add_vo( vo_type, player_no )
buttons: {
OK: function() {
// add the new vehicle/ordnance
- var data = $sel.select2( "data" ) ;
- if ( ! data )
+ // FUDGE! $sel.select("data") returns the wrong thing if the entries are filtered?!?!
+ var $elem = $( "#select-vo .select2-results__option--highlighted" ) ;
+ if ( $elem.length === 0 )
return ;
- var $img = $( "#"+data[0]._resultId ).find( "img[class='vasl-image']" ) ;
+ var sel_index = $elem.children( ".vo-entry" ).data( "index" ) ;
+ var $img = $elem.find( "img[class='vasl-image']" ) ;
var vo_image_id = $img.data( "vo-image-id" ) ;
- do_add_vo( vo_type, player_no, entries[data[0].id], vo_image_id ) ;
+ do_add_vo( vo_type, player_no, entries[sel_index], vo_image_id ) ;
$(this).dialog( "close" ) ;
},
Cancel: function() { $(this).dialog( "close" ) ; },
diff --git a/vasl_templates/webapp/tests/test_vehicles_ordnance.py b/vasl_templates/webapp/tests/test_vehicles_ordnance.py
index 641e8b8..26c3ab9 100644
--- a/vasl_templates/webapp/tests/test_vehicles_ordnance.py
+++ b/vasl_templates/webapp/tests/test_vehicles_ordnance.py
@@ -7,6 +7,7 @@ import json
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
+from selenium.common.exceptions import WebDriverException
from vasl_templates.webapp.tests.test_scenario_persistence import load_scenario, save_scenario
from vasl_templates.webapp.tests.utils import \
@@ -485,9 +486,13 @@ def add_vo( webdriver, vo_type, player_no, name ):
assert len(matches) == 1
elem = matches[0]
webdriver.execute_script( "arguments[0].scrollIntoView()", elem )
+ # FUDGE! Selecting the required entry is flaky, and we sometimes need to do it twice (Firefox :-/).
ActionChains( webdriver ).click( elem ).perform()
+ try:
+ ActionChains( webdriver ).click( elem ).perform()
+ except WebDriverException as ex:
+ assert "TypeError: rect is undefined" in str(ex)
if find_child( "#select-vo" ).is_displayed():
- # FUDGE! Clicking on the element sometimes make the dialog close :-/
click_dialog_button( "OK" )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -