Skip to content

Instantly share code, notes, and snippets.

View buru's full-sized avatar
🇺🇦

Pavlo Zahozhenko buru

🇺🇦
View GitHub Profile
@buru
buru / clear_ajax_chosen_select.js
Created June 7, 2013 15:09
Clear initialized Ajax-Chosen select to init it in some different way (e.g., changing url or GET/POST params). It's not as easy as it sounds...
$(".chzn-select").html('<option></option>');
$(".chzn-select").trigger("liszt:updated");
$(".chzn-select").next('.chzn-container').find(".search-field > input, .chzn-search > input").unbind('keyup');
// then reinit ajax-chosen as usual
$(".chzn-select").ajaxChosen({ ... });
@buru
buru / select_from_ajax_chosen.rb
Created June 7, 2013 15:00
Select the first item from Ajax-Chosen field using Capybara with Selenium web driver
def select_from_ajax_chosen(item_text, field_id)
within "##{field_id}_chzn" do
find('a.chzn-single').click
input = find("div.chzn-search input")
item_text.each_char do |char|
input.native.send_keys char
end
sleep 1
input.native.send_keys :arrow_down
input.native.send_keys :return