2014-03-19 6 views
1
정의되지 않은

의 방법 'scrollTop'을 호출 할 수 없습니다 : 가 정의되지 않은부트 스트랩 모달 : 나는 다음과 같은 오류가 왜 이해가 안

의 방법 'scrollTop'을 호출 할 수 없습니다 내가 모달 표시 링크를 클릭합니다.

저는 jQuery 1.11, 부트 스트랩 3.1.1을 부릅니다. 문제가 발생

#forgot_password.modal{tabindex: -1, role: 'dialog', "aria-labelledby" => t('.title'), "aria-hidden" => true} 
    .modal-dialog 
    .modal-content 
     .modal-header 
     %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} × 
     %h4= t('.title') 
     .modal-body 
     .form_wrapper 
      .innertxt= t('.explanation') 
      .forgot_password_form 
      = form_for :forgot_password, url: forgot_password_path do |f| 
       = text_field_tag :email, '', placeholder: t('email'), size: 50, autofocus: true 
       = submit_tag t('send'), :class => 'btn' 

부트 스트랩 :

.forgot_password.pull-right = link_to t('.forgot_password'), '#forgot_password', data: { target: "#forgot_password", toggle: "modal" }, tabindex: 5

모달 : (방법 Modal.prototype 모달 표시 코드 (HAML)

버튼에 대해

.show
)

this.backdrop(function() { 
     var transition = $.support.transition && that.$element.hasClass('fade') 

     if (!that.$element.parent().length) { 
     that.$element.appendTo(document.body) // don't move modals dom position 
     } 

     that.$element 
     .show() 
     .scrollTop(0) 
... 

표시 오류 :

TypeError: 'undefined' is not an object (evaluating 'that.$element 
       .show() 
       .scrollTop') 

나는 that.element가 null이거나 정의이며 코드를 나누기 추측. 하지만 그것은 내 테스트 사양을 깰 때문에 수정/해결 방법을 찾고 있어요! (카피 바라와 루비)

나는 http://getbootstrap.com/javascript/#modals에 대한 예제를 따라 왔으며, 지금까지 나는 그들과 나의 코드 사이에 차이점을 보지 못했다. HTML 대신 javascript를 사용하여 모달을 열려고했지만 정확하게 동일합니다.

아이디어가 있으십니까?

편집 : 루비/카피 바라 코드

click_link 'Glemt adgangskode?'# Forgotten password? 
    sleep 3 
    within_frame('form_login') do 
    fill_in 'email', with: '[email protected]' 
    click_button 'Send' 
    end 

Edit2가 : 그런데이 모든 것이 잘 작동, 모달 팝업 정확하게는, 그냥 실제로 영향을주지 않습니다 자바 스크립트 오류가 발생했습니다 사용법. 그러나 이것을 이해하고 고치고 싶습니다.

답변

3

제 실수였습니다.

실제로 저는 몇 주 전에 jQuery.show() 메소드를 오버라이드하고 return 문을 잊어 버렸습니다. 그래서 scrollTop은 실제로 undefined 요소를 기반으로했습니다.

$(function(){ 
    /** 
    * Override hide function. 
    */ 
    // Store a reference to the original remove method. 
    var originalShowMethod = $.fn.show; 

    $.fn.show = function(){ 
    var self = $(this); 

    // Remove CSS classes that hide the element. 
    self.removeClass('hidden hide invisible'); 

    // Apply the original method. 
    return originalShowMethod.apply(this, arguments); 
    } 
}); 

이제 더 잘 작동합니다. 오버 라이드 (override)는 show() 함수를 호출 할 때 CSS 클래스를 자동으로 제거 할 수있게 해줍니다. 죄송합니다!

관련 문제