必須フィールドの入力が済むまでボタンを無効にする - Greg Collins
in

InfoPath Dev

This Blog

Syndication

Archives

Greg Collins

必須フィールドの入力が済むまでボタンを無効にする

フォーム上に配置したボタンを、すべての必須のフォーム フィールドの入力が済むまでクリックできないようにすることができます。このためには、条件付き書式を使用します。条件付き書式の複雑さはフォームによって異なります。

このタスクでは、送信ボタンがあるシンプルなフォームを作成します。次に条件付き書式を追加して、すべての必須フォーム フィールドの入力が済むまでボタンを無効にします。まず、新しい空白のフォームを作成しておきます。

スキーマの作成:

 [Data Source] 作業ウィンドウを開きます。

    1. <!--[if !supportLists]-->Name」という名前のテキスト フィールドを追加します。このフィールドは必須です。
    2. <!--[if !supportLists]--><!--[endif]-->Address」および「Phone」という名前の 2 つのテキスト フィールドを追加します。
    3. <!--[if !supportLists]-->Email」という名前のテキスト フィールドを追加します。このフィールドは必須です。
    4. Comments」という名前のリッチテキストフィールドを追加します

       リッチ テキスト フィールドが必須であることを要求するカスタムのデータ検証を追加する

      リッチ テキスト フィールドが必須であることをデータ ソースで指定することはできないので、カスタムのデータ検証によって手動で指定する必要があります。リッチ テキスト フィールドは、通常のテキスト フィールドとは動作が異なり、空白かどうかを単純にチェックすることはできません。これは、“is blank (が空白である) の結果が常に正確であるとは限らないからです。

      1. <!--[if !supportLists]--> <!--[endif]-->[Data Source] 作業ウィンドウの [Comments] をダブルクリックします。
      2. <!--[if !supportLists]--> <!--[endif]-->[Field Or Group Properties] ダイアログ ボックスの [Validation And Event Handlers] タブで [Add] をクリックします。
      3. <!--[if !supportLists]--> <!--[endif]-->1 つ目のボックスの一覧の [Expression] をクリックし、次の式を入力します。

      not(.//node())

      1. [ScreenTip] ボックスに「Cannot be blank 」と入力し ( 1 を参照)[OK] 2 回クリックします。


       1 リッチ テキスト フィールドが必須であることを要求するカスタム検証

      ビューの設計

      1. <!--[if !supportLists]--> <!--[endif]-->[myFields] を右クリックし、[Controls In Layout Table] をクリックします。
      2. <!--[if !supportLists]--> <!--[endif]-->[Controls] 作業ウィンドウから、ボタンをビューに挿入します。
      3. <!--[if !supportLists]--><!--[endif]-->ボタンをダブルクリックします。
      4. <!--[if !supportLists]--> <!--[endif]-->[Button Properties] ダイアログ ボックスの [General] タブで、ラベルを「Submit」に変更し、ID を「btnSubmit」に変更します。
      5. <!--[if !supportLists]--> <!--[endif]-->[Rules] をクリックし、[Add] をクリックします。
      6. <!--[if !supportLists]--> <!--[endif]-->動作規則に「Submit」という名前を付け、[Add Action] をクリックします。
      7. <!--[if !supportLists]--> <!--[endif]-->[Action] ボックスの一覧の [Show A Dialog Box Message] をクリックします。 
      8. <!--[if !supportLists]--> <!--[endif]-->メッセージとして「Form Submitted」と入力し、[OK] 3 回クリックします。

      ボタンを無効にするための条件付き書式を追加する

      1. <!--[endif]-->[Button Properties] ダイアログ ボックスの [Display] タブで、[Conditional Formatting] をクリックし、[Add] をクリックします。
      2. <!--[if !supportLists]--> <!--[endif]-->1 つ目のボックスの一覧の [Name] をクリックし、2 つ目のボックスの一覧の [Is Blank] をクリックします。次に、[And] をクリックし、[And] の代わりに [Or] をクリックします。
      3. <!--[if !supportLists]-->3.     <!--[endif]-->1 つ目のボックスの一覧の [Email] をクリックし、2 つ目のボックスの一覧の [Is Blank] をクリックします。次に、[And] をクリックし、[And] の代わりに [Or] をクリックします。
      4. <!--[if !supportLists]--> <!--[endif]-->1 つ目のボックスの一覧の [The Expression] をクリックし、次の式を入力します。

      not(my:Comments//node())

      1. [Disable This Control] チェック ボックスをオンにし ( 2 を参照)[OK] 3 回クリックします。


       2 ボタンを無効にするために必要な条件

      確認

      フォームを初めてプレビューすると、[Name][Email][Comments] の各フィールドは、必須フィールドであることを示す赤いアスタリスク付きで表示されます。また、[Submit] ボタンが無効になっています。必須フィールドに入力すると、[Submit] ボタンが有効になるので、その後フォームを送信できます。図 3 は、必須フィールドに入力する前と入力した後のフォームを示しています。


      3 すべての必須フィールドの入力が済むまで送信ボタンは無効です

      ©2005 Greg Collins. All rights reserved. Licensed to Autonomy Systems, LLC for display on InfoPathDev.com.

      Comments

      No Comments

      About Kaoru Okumura

      Program Manager, Qdabra.com Kaoru worked for ten years at Microsoft as a program manager, and many years at IBM Tokyo Research Lab as an advisory researcher. She led projects on natural language related research and products including Japanese search and proofing tools. Kaoru holds a Master of Science in Mathematics from Kyushu University, and BA from International Christian University. She enjoys performing Butoh dance, and taking photography.
      Copyright © 2003-2019 Qdabra Software. All rights reserved.
      View our Terms of Use.