2012-04-30 3 views
0

나는 사용자 정의 모듈의 간단한 드루팔 양식을 가지고있다.처리하는 동안 Drupal textfield ahah 이벤트가 필드를 사용 중지하지 못하게하는 가장 좋은 방법은 무엇입니까? <code>div</code>을 채우는 <code>ahah</code>를 통해 입력 한 텍스트에 대한 몇 가지 정보를 검색해야 <code>textfield</code>를 종료 할 경우

텍스트 필드의 ahah 이벤트가 처리되는 동안 사용자가 양식을 빨리 제출하는 경우를 제외하고는 정상적으로 작동합니다.

그것은 AHAH 이벤트가 텍스트 필드 처리되는 동안처럼 보이는 물론이 값이 제출되지이다 의미 사용할 수 없습니다. 즉, 텍스트 필드가 필수 필드이므로 유효성 검사가 실패 함을 의미하므로 사용자는 적절한 오류가있는 양식으로 리턴됩니다. 이 경우 텍스트 필드는 항상 비어 있습니다.

사용자가 이벤트가 끝나기를 기다리면 텍스트 필드에서 Enter 키를 사용하여 제출할 때처럼 텍스트 필드가 사용 가능으로 설정되고 예상 한대로 작동합니다 (이벤트가 발생하지 않기 때문에 텍스트 필드 데이터를 검색하는 동안 비활성화되지 않음).

이 AHAH 이벤트가 처리되는 것 동안 텍스트 필드의 비활성화를 비활성화하는 방법, 또는 다른 해결 방법이 있습니까? 텍스트 필드의

예 : 사전에 어떤 도움

$form['id'] = array(
    '#type' => 'textfield', 
    '#title' => t('Crop No.'), 
    '#default_value' => $crop['id'] ? $crop['id'] : '', 
    '#size' => 6, 
    '#disabled' => $disabled, 
    '#ahah' => array(
     'path' => 'spcs-myspuds/yields/js/crop/description/' . $crop_idx, 
     'wrapper' => 'spcs-myspuds-yields-edit-crop-description-row-' . $crop_idx, 
     'effect' => 'fade', 
     'progress' => array(
      'type' => 'none', 
     ), 
    ), 
); 

감사합니다.

답변

0

해결 방법이 있습니다.

나는 (대만족 아니라!), Drupal.ahah.prototype.beforeSubmit를 대체하기 위해 제출하기 전에 입력을 비활성화하는 기능을했다. 입력의 무능력으로 배치 한 작은 변화 ahah.js/기타에 기재된이 Drupal.ahah.prototype.beforeSubmit의 사본이다

$(document).ready(function() { 
    if (typeof beforeSubmitOverride == 'undefined' || beforeSubmitOverride == false) { 
    Drupal.ahah.prototype.beforeSubmit = function (form_values, element, options) { 
     // Disable the element that received the change. 
     // IMiJ: Unless it's a text input, otherwise we could submit while element is diabled and loose data. 
     if ($(this.element).attr('type') != 'text') { 
     $(this.element).addClass('progress-disabled').attr('disabled', true); 
     } 

     // Insert progressbar or throbber. 
     if (this.progress.type == 'bar') { 
     var progressBar = new Drupal.progressBar('ahah-progress-' + this.element.id, eval(this.progress.update_callback), this.progress.method, eval(this.progress.error_callback)); 
     if (this.progress.message) { 
      progressBar.setProgress(-1, this.progress.message); 
     } 
     if (this.progress.url) { 
      progressBar.startMonitoring(this.progress.url, this.progress.interval || 1500); 
     } 
     this.progress.element = $(progressBar.element).addClass('ahah-progress ahah-progress-bar'); 
     this.progress.object = progressBar; 
     $(this.element).after(this.progress.element); 
     } 
     else if (this.progress.type == 'throbber') { 
     this.progress.element = $('<div class="ahah-progress ahah-progress-throbber"><div class="throbber">&nbsp;</div></div>'); 
     if (this.progress.message) { 
      $('.throbber', this.progress.element).after('<div class="message">' + this.progress.message + '</div>'); 
     } 
     $(this.element).after(this.progress.element); 
     } 
    }; 
    }; 
    beforeSubmitOverride = true; 
}); 

:

난 ( drupal_add_js 사용) 내 모듈에서 다음 스크립트를 포함 if 문을 사용하여 텍스트 필드를 비활성화하지 않았는지 확인하십시오.

DOM 준비가 완료되면 프로토 타입을 다시 정의 할 수 있도록하기 위해 몇 줄로 둘러 쌉니다.

"disable"=> false와 같은 설정이 전달 된 경우에만 입력 사용 중지를 중지하는 것이 더 좋을 수 있지만 위의 경우는 하나의 맞춤 모듈에 대해 하나의 페이지에서 하나의 사례에 대해 작동했습니다. 고치다.

-1

텍스트 필드의 #required 속성 TRUE를 필수 입력란으로 설정할 수 있습니다. #disabled 속성을 false로 설정하여 문제가 발생하지 않았는지 확인합니다. #ahah 이벤트가 validate 기능이 처리 중일 때

+0

대답 나빈 주셔서 감사합니다,하지만 #REQUIRED 및 #disabled 매개 변수에 대한 참조는이 경우 관련성이없는 (그리고 어쨌든, 그렇지 않으면 데이터가 AHAH 이벤트를 트리거 입력 할 수없는 테스트 시나리오에서 거짓 #disabled)입니다. 문제는 처리하는 동안 ahah가 입력을 비활성화하는 문제이며 ahah 이벤트는 유효성 검사를 수행하지 않거나 유효성 검사 후크를 트리거하지 않습니다. – ianmjones