0
단일 선택 드롭 다운이 있습니다. 사용자가 선택을하면 양식이 jquery와 함께 제출되기를 원합니다.단일 선택 드롭 다운시 jquery로 select2 양식 제출
$(document).on('page:change', function(){
function matchStart(params, data) {
params.term = params.term || '';
if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) {
return data;
}
return false;
}
$("select#user_country").select2({
matcher: function(params, data) {
return matchStart(params, data);
},
placeholder: "Select a country",
})
$("select#user_country").on('select2:select', function (event) {
return ('form#selectcountry').submit();
});
});
레일보기 :
<%= form_tag users_path, method: :get, id: 'selectcountry' do |f| %>
<%= select_tag "country", options_from_collection_for_select(ISO3166::Country.countries.sort_by(&:name), 'un_locode', 'name'), :include_blank => true %>
<%= submit_tag "Search", :name => "nil", :id => "submit-me" %>
<% end %>
Link here to 'select2:select' documentation
$('select').on('select2:select', function (evt) {
// Do something
});
편집
다음과 같이내 jQuery 코드입니다 0
이벤트 리스너가 작동한다는 것을 잊어 버렸습니다. 경고 메시지와 함께 테스트 했으므로 폼을 제출하지 않았습니다.