1

Tapestry 5 では、個々のフォーム フィールドが完了し、クライアント側の検証に合格したときに (Google アナリティクス経由で) ログを記録する必要があります。

フォームが送信されていない場合でも、個々のフィールドごとにリアルタイムでこれを行う必要があるため、フォームの送信を待ってサーバーでこれを行うことはオプションではありません。

Tapestry 5 によって提供される JavaScript クライアント側検証の成功/失敗にフックする (すぐに使える) 方法はありますか?

私が考えることができる2つの可能性は次のとおりです。

  1. 成功/失敗イベントへのコールバック関数を提供する Tapestry API。
  2. 成功/失敗時にいくつかの Tapestry カスタム イベントをリッスンします。

しかし、これらの既存のいずれかに関するドキュメントには何も見つかりません。これらのオプションのいずれかが可能ですか、またはこれを達成する別の方法はありますか?

4

2 に答える 2

2

クライアント側のイベントリスナーをアタッチして、目的を達成できる場合があります。Tapestry.FormEventManager.handleSubmittapestry.jsを見てみましょう。フォームの送信により、次のクライアント側イベントが発生します。

/**
 * Event that allows observers to perform cross-form validation after
 * individual fields have performed their validation. The form element is
 * passed as the event memo. Observers may set the validationError property
 * of the Form's Tapestry object to true (which will prevent form
 * submission).
 */
FORM_VALIDATE_EVENT: "tapestry:formvalidate",

/**
 * Event fired just before the form submits, to allow observers to make
 * final preparations for the submission, such as updating hidden form
 * fields. The form element is passed as the event memo.
 */
FORM_PREPARE_FOR_SUBMIT_EVENT: "tapestry:formprepareforsubmit",

/**
 * Form event fired after prepare.
 */
FORM_PROCESS_SUBMIT_EVENT: "tapestry:formprocesssubmit",

/**
 * Event, fired on a field element, to cause observers to validate the
 * input. Passes a memo object with two keys: "value" (the raw input value)
 * and "translated" (the parsed value, usually meaning a number parsed from
 * a string). Observers may invoke Element.showValidationMessage() to
 * identify that the field is in error (and decorate the field and show a
 * popup error message).
 */
FIELD_VALIDATE_EVENT: "tapestry:fieldvalidate",

/**
 * Event notification, on a form object, that is used to trigger validation
 * on all fields within the form (observed by each field's
 * Tapestry.FieldEventManager).
 */
FORM_VALIDATE_FIELDS_EVENT: "tapestry:validatefields",
于 2013-07-12T07:43:21.897 に答える