File tree Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Expand file tree Collapse file tree 2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change 9999 expect ( all ( :css , 'input.ra-filtering-select-input' ) . count ) . to eq 1
100100 end
101101
102+ it 'does not lose options on browser back' do
103+ visit edit_path ( model_name : 'player' , id : player . id )
104+ find ( '.team_field .dropdown-toggle' ) . click
105+ find ( 'li.ui-menu-item a' , text : /Clear/ ) . click
106+ click_link 'Show'
107+ is_expected . to have_content 'Details for Player'
108+ page . go_back
109+ find ( '.team_field input.ra-filtering-select-input' ) . set ( 'Los' )
110+ page . execute_script ( "document.querySelector('.team_field input.ra-filtering-select-input').dispatchEvent(new KeyboardEvent('keydown'))" )
111+ is_expected . to have_selector ( 'ul.ui-autocomplete li.ui-menu-item a' , text : 'Los Angeles Dodgers' )
112+ end
113+
102114 context 'when using remote requests' do
103115 before do
104116 RailsAdmin . config Player do
Original file line number Diff line number Diff line change @@ -216,11 +216,20 @@ import I18n from "./i18n";
216216 minLength : this . options . minLength ,
217217 source : this . _getSourceFunction ( this . options . source ) ,
218218 select : function ( event , ui ) {
219- var option = $ ( "<option>" )
220- . attr ( "value" , ui . item . id )
221- . attr ( "selected" , "selected" )
222- . text ( ui . item . value ) ;
223- self . element . html ( option ) . trigger ( "change" , ui . item . id ) ;
219+ var option = self . element . find (
220+ `option[value="${ CSS . escape ( ui . item . id ) } "]`
221+ ) ;
222+ self . element . find ( "option[selected]" ) . attr ( "selected" , false ) ;
223+ if ( option . length > 0 ) {
224+ option . attr ( "selected" , "selected" ) ;
225+ } else {
226+ option = $ ( "<option>" )
227+ . attr ( "value" , ui . item . id )
228+ . attr ( "selected" , true )
229+ . text ( ui . item . value ) ;
230+ self . element . append ( option ) ;
231+ }
232+ self . element . trigger ( "change" , ui . item . id ) ;
224233 self . _trigger ( "selected" , event , {
225234 item : option ,
226235 } ) ;
You can’t perform that action at this time.
0 commit comments