Changeset 3745238
- Timestamp:
- 10/14/2026 03:55:59 AM (10 days ago)
- Location:
- kakunin-modal-for-contact-form-7/trunk
- Files:
-
- 3 edited
-
assets/js/kakunin-modal-for-contact-form-7.js (modified) (7 diffs)
-
kakunin-modal-for-contact-form-7.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
kakunin-modal-for-contact-form-7/trunk/assets/js/kakunin-modal-for-contact-form-7.js
r3728560 r3745238 351 351 field.name.startsWith('_wpcf7') || 352 352 !field.name || 353 // quiz / captchar は CF7 がメールに含めない項目なので表示しない 354 field.classList.contains('wpcf7-quiz') || 355 field.classList.contains('wpcf7-captchar') || 353 356 this.isFieldInHiddenGroup(field) 354 357 ) { … … 379 382 // セレクトボックス 380 383 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(', '); 391 393 } 392 394 // テキストエリア・テキストボックス … … 436 438 const item = field.closest('.wpcf7-list-item'); 437 439 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; 439 447 } 440 448 … … 579 587 } 580 588 581 // 7. name属性から取得(最終手段) 582 return field.name || '';589 // 7. name属性から取得(最終手段)。checkbox 等の末尾の [] は外す 590 return (field.name || '').replace(/\[\]$/, ''); 583 591 } 584 592 … … 624 632 */ 625 633 validateRequiredFields() { 626 // CF7必須フィールド(wpcf7-validates-as-required)の空チェック 634 // CF7必須フィールドの空チェック 635 // - `*` 付きのタグには wpcf7-validates-as-required が付く 636 // - radio / quiz / captchar は `*` が無くても CF7 側で常に必須扱いなので対象に含める 627 637 // 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 ); 629 641 for (const field of requiredFields) { 630 642 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')) { 634 646 if (!field.querySelector('input:checked')) return false; 635 647 continue; … … 639 651 const checked = this.form.querySelector(`input[name="${name}"]:checked`); 640 652 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; 641 657 } else { 642 658 if (!field.value || field.value.trim() === '') return false; … … 644 660 } 645 661 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 } 649 669 650 670 return true; -
kakunin-modal-for-contact-form-7/trunk/kakunin-modal-for-contact-form-7.php
r3728560 r3745238 5 5 * Plugin URI: https://torigoedesign.com/kakunin-modal-for-contact-form-7/ 6 6 * 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. 17 * Version: 0.9.2 8 8 * Requires at least: 5.0 9 9 * Requires PHP: 7.4 … … 34 34 35 35 // プラグインのバージョン 36 define('CF7_CONFIRM_VERSION', '0.9. 1');36 define('CF7_CONFIRM_VERSION', '0.9.2'); 37 37 38 38 // プラグインのスラッグ(テキストドメイン・スクリプトハンドル・設定ページのslugに共通で使用) -
kakunin-modal-for-contact-form-7/trunk/readme.txt
r3728560 r3745238 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 0.9. 17 Stable tag: 0.9.2 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 93 93 == Changelog == 94 94 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 95 103 = 0.9.1 = 96 104 * 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)