레일 애플 리케이션에서 양식을 수정하는 방법을 알아 내려고합니다.jQuery가있는 레일 4 - 양식의 선택 기능
양식에 현재 2 개의 질문이 있습니다.
첫 번째 질문은 사용자에게 조직을 선택하도록 요청합니다. 원하는 조직이 목록에 없으면 다른 조직을 선택할 수있는 옵션이 있습니다.
다른 사람이 선택하면 두 번째 질문을 표시하고 싶습니다. 내 양식에
, 나는이 :
내 응용 프로그램/자산/자바 스크립트/organisation_requests.js에서<%= simple_form_for(@organisation_request) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :organisation_id, collection: @all_organisations << ['other', nil] %>
</div>
<div id="organisation_request_name_content" class="content hidden">
<div class="form-inputs">
<%= f.input :name %>
</div>
</div>
<div class="form-actions">
<%= f.button :submit, "Create", :class => 'formsubmit' %>
</div>
<% end %>
, 나는이 : 나는이 모든 저장하면
jQuery(document).ready(function() {
jQuery("#organisation_request_organisation_id").on('select', function() {
if (jQuery(this)[0] == 'other') {
jQuery('#organisation_request_name_content').removeClass('hidden');
} else {
jQuery('#organisation_request_name_content').addClass('hidden');
}
});
});
그것을 시도 - 두 번째 질문은 숨겨져 있지만 첫 번째 질문에 대한 입력으로 다른 질문을 선택하면 밝혀지지 않습니다.
어디서 잘못 본 사람이 있습니까?
dom 요소를 배열로 취급합니다. 힌트 :'jQuery (this)'는 무엇을 참조합니까? 귀하의 콘솔을 사용하십시오 ... –
@RubyRacer - 나는 그 중 어떤 것도 이해하지 못할까 두렵습니다. 나는 (이)이 논쟁을 의미한다고 생각했다. 나는 당신이 제안한 바를 전혀 확신하지 못합니다. 해결책을 찾기 위해 내 레일 콘솔을 사용합니다. – Mel
브라우저에서 개발 콘솔을 사용한다는 의미입니다. '이것은 요소를 나타냅니다. 이 [0]이 (가) 문자열이 될 것이라고 어떻게 예상합니까? –