Plugin Directory

Changeset 3745238


Ignore:
Timestamp:
10/14/2026 03:55:59 AM (10 days ago)
Author:
torigoedesign
Message:

Update trunk to 0.9.2

Location:
kakunin-modal-for-contact-form-7/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kakunin-modal-for-contact-form-7/trunk/assets/js/kakunin-modal-for-contact-form-7.js

    r3728560 r3745238  
    351351        field.name.startsWith('_wpcf7') ||
    352352        !field.name ||
     353        // quiz / captchar は CF7 がメールに含めない項目なので表示しない
     354        field.classList.contains('wpcf7-quiz') ||
     355        field.classList.contains('wpcf7-captchar') ||
    353356        this.isFieldInHiddenGroup(field)
    354357      ) {
    … …  
    379382      // セレクトボックス
    380383      else if (field.tagName === 'SELECT') {
    381         const selectedOption = field.options[field.selectedIndex];
    382         if (selectedOption) {
    383           value = selectedOption.value; // まずvalueを取得
    384           // valueが空の場合はスキップ
    385           if (!value || value === '') {
    386             return;
    387           }
    388           // 表示用にtextを使用
    389           value = selectedOption.text;
    390         }
     384        // 複数選択にも対応。空値(include_blank / first_as_label の先頭項目)は除く
     385        value = Array.from(field.selectedOptions)
     386          .filter((option) => option.value !== '')
     387          .map((option) => option.text)
     388          .join(', ');
     389      }
     390      // ファイル(field.value は C:\fakepath\ 付きになるためファイル名を使う)
     391      else if (field.type === 'file') {
     392        value = Array.from(field.files).map((file) => file.name).join(', ');
    391393      }
    392394      // テキストエリア・テキストボックス
    … …  
    436438    const item = field.closest('.wpcf7-list-item');
    437439    const label = item ? item.querySelector('.wpcf7-list-item-label') : null;
    438     return label ? label.textContent.trim() : field.value;
     440    const text = label ? label.textContent.trim() : field.value;
     441    // free_text オプションの自由記述欄。チェック済みで入力があれば CF7 のメールと同じ「文言 自由記述」の形にする
     442    const freeText = item ? item.querySelector('input.wpcf7-free-text') : null;
     443    if (freeText && field.checked && freeText.value.trim()) {
     444      return `${text} ${freeText.value.trim()}`;
     445    }
     446    return text;
    439447  }
    440448
    … …  
    579587    }
    580588
    581     // 7. name属性から取得(最終手段)
    582     return field.name || '';
     589    // 7. name属性から取得(最終手段)。checkbox 等の末尾の [] は外す
     590    return (field.name || '').replace(/\[\]$/, '');
    583591  }
    584592
    … …  
    624632   */
    625633  validateRequiredFields() {
    626     // CF7必須フィールド(wpcf7-validates-as-required)の空チェック
     634    // CF7必須フィールドの空チェック
     635    // - `*` 付きのタグには wpcf7-validates-as-required が付く
     636    // - radio / quiz / captchar は `*` が無くても CF7 側で常に必須扱いなので対象に含める
    627637    // CF7 Conditional Fieldsで非表示のグループ内のフィールドはスキップ
    628     const requiredFields = this.form.querySelectorAll('.wpcf7-validates-as-required');
     638    const requiredFields = this.form.querySelectorAll(
     639      '.wpcf7-validates-as-required, .wpcf7-form-control.wpcf7-radio, .wpcf7-quiz, .wpcf7-captchar'
     640    );
    629641    for (const field of requiredFields) {
    630642      if (this.isFieldInHiddenGroup(field)) continue;
    631       // [checkbox*] は必須クラスが各 input ではなく
    632       // <span class="wpcf7-form-control wpcf7-checkbox"> ラッパーに付くため、中の input の選択状態で判定する
    633       if (field.classList.contains('wpcf7-checkbox')) {
     643      // [checkbox*] と [radio] は必須クラスが各 input ではなく
     644      // <span class="wpcf7-form-control wpcf7-checkbox|wpcf7-radio"> ラッパーに付くため、中の input の選択状態で判定する
     645      if (field.classList.contains('wpcf7-checkbox') || field.classList.contains('wpcf7-radio')) {
    634646        if (!field.querySelector('input:checked')) return false;
    635647        continue;
    … …  
    639651        const checked = this.form.querySelector(`input[name="${name}"]:checked`);
    640652        if (!checked) return false;
     653      } else if (field.tagName === 'SELECT') {
     654        // multiple + include_blank で空欄と値を同時に選ぶと select.value は空欄を返すため、
     655        // CF7 と同じく空値を除いた上で選択があるかで判定する
     656        if (!Array.from(field.selectedOptions).some((option) => option.value.trim() !== '')) return false;
    641657      } else {
    642658        if (!field.value || field.value.trim() === '') return false;
    … …  
    644660    }
    645661
    646     // CF7 acceptanceフィールド(未チェックの必須acceptance)
    647     const uncheckedAcceptance = this.form.querySelectorAll('.wpcf7-acceptance:not(.optional) input[type="checkbox"]:not(:checked)');
    648     if (uncheckedAcceptance.length > 0) return false;
     662    // CF7 acceptance(optional 以外)。invert 付きは「チェックしていない状態」が同意
     663    const acceptances = this.form.querySelectorAll('.wpcf7-acceptance:not(.optional)');
     664    for (const acceptance of acceptances) {
     665      if (this.isFieldInHiddenGroup(acceptance)) continue;
     666      const checkbox = acceptance.querySelector('input[type="checkbox"]');
     667      if (checkbox && checkbox.checked === acceptance.classList.contains('invert')) return false;
     668    }
    649669
    650670    return true;
  • kakunin-modal-for-contact-form-7/trunk/kakunin-modal-for-contact-form-7.php

    r3728560 r3745238  
    55 * Plugin URI: https://torigoedesign.com/kakunin-modal-for-contact-form-7/
    66 * Description: Adds a confirmation modal to Contact Form 7 forms so visitors can review their input before the form is submitted.
    7  * Version: 0.9.1
     7 * Version: 0.9.2
    88 * Requires at least: 5.0
    99 * Requires PHP: 7.4
    … …  
    3434
    3535// プラグインのバージョン
    36 define('CF7_CONFIRM_VERSION', '0.9.1');
     36define('CF7_CONFIRM_VERSION', '0.9.2');
    3737
    3838// プラグインのスラッグ(テキストドメイン・スクリプトハンドル・設定ページのslugに共通で使用)
  • kakunin-modal-for-contact-form-7/trunk/readme.txt

    r3728560 r3745238  
    55Tested up to: 7.1
    66Requires PHP: 7.4
    7 Stable tag: 0.9.1
     7Stable tag: 0.9.2
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    9393== Changelog ==
    9494
     95= 0.9.2 =
     96* Radio buttons, quiz and CAPTCHA (`[captchar]`) fields are now treated as required, matching Contact Form 7. The submit button stays disabled until an option is selected or the field is filled in.
     97* Acceptance checkboxes with the `invert` option now work. The form can be submitted while the box is unchecked. Acceptance checkboxes inside a hidden group of the Conditional Fields plugin are ignored.
     98* Multiple-select fields now show every selected option in the modal, separated by commas. A required multiple select with `include_blank` now accepts the blank option selected together with another option. A select with no option chosen is shown as empty when empty fields are set to be displayed.
     99* File fields now show only the file name in the modal, without the `C:\fakepath\` prefix added by the browser.
     100* The free text of checkbox and radio options with `free_text` is now shown next to the option label, in the same form as the email Contact Form 7 sends. Quiz and CAPTCHA answers are no longer shown in the modal.
     101* When a field label falls back to the name attribute, the trailing `[]` is removed.
     102
    95103= 0.9.1 =
    96104* Fixed the submit button staying disabled on forms with a required checkbox field (`[checkbox*]`). Contact Form 7 puts the required class on the wrapper of the options, so the wrapper is now checked for a selected option.
Note: See TracChangeset for help on using the changeset viewer.