メニューを切り替える
個人設定メニューを切り替える
個人メニューを切り替える
ログインしていません
編集を行うと、IPアドレスが公開されます。

「MediaWiki:Gadget-SearchInshokuten.js」の版間の差分

MediaWikiインターフェイスページ
編集の要約なし
タグ: 手動差し戻し
編集の要約なし
タグ: 差し戻し済み
1行目: 1行目:
if ( document.querySelector('#searchForm') ) {
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('searchForm').addEventListener('submit', function (e) {
   const form = document.getElementById('searchForm');
   const searchText = document.getElementById('searchText');
   if (!form) return;
   const genre = document.getElementById('genre');
  const station = document.getElementById('station');
  const budget_min = document.getElementById('budget_min');
  const budget_max = document.getElementById('budget_max');


   if (searchText.value === '') {
   // ---- SUBMIT ----
     searchText.removeAttribute('name'); // 空のとき name属性を削除
  form.addEventListener('submit', function () {
  }
     const ids = ['searchText','genre','station','budget_min','budget_max'];
  if (genre.value === '') {
    ids.forEach(id => {
    genre.removeAttribute('name'); // 空のとき name属性を削除
      const el = document.getElementById(id);
  }
      if (el && el.value.trim() === '') {
  if (station.value === '') {
        el.removeAttribute('name');
    station.removeAttribute('name'); // 空のとき name属性を削除
      }
  }
     });
  if (budget_min.value === '') {
   });
    budget_min.removeAttribute('name'); // 空のとき name属性を削除
  }
  if (budget_max.value === '') {
     budget_max.removeAttribute('name'); // 空のとき name属性を削除
   }
});


document.addEventListener('DOMContentLoaded', function () {
  // ---- LOAD FROM URL ----
   const params = new URLSearchParams(window.location.search);
   const params = new URLSearchParams(window.location.search);
   params.forEach((value, key) => {
   params.forEach((value, key) => {
     // input, select, checkbox, radio 全対応
     document.querySelectorAll(`[name="${key}"]`).forEach(el => {
    const el = document.querySelector(`[name="${key}"]`);
      if (el.type === "checkbox" || el.type === "radio") {
    if (!el) return;
        if (el.value === value) el.checked = true;
      } else {
        el.value = value;
      }
    });
  });


    // checkbox / radio (name[] の対応含む)
  // ---- CLEAR BUTTON ----
    if (el.type === "checkbox" || el.type === "radio") {
      document.querySelectorAll(`[name="${key}"]`).forEach(input => {
        if (input.value === value) {
          input.checked = true;
        }
      });
    } else {
      // text / select など
      el.value = value;
    }
  });
 
   const clearBtn = document.querySelector('.clear-btn');
   const clearBtn = document.querySelector('.clear-btn');
   const form    = document.getElementById('searchForm');
   if (clearBtn) {
 
    clearBtn.addEventListener('click', function () {
  clearBtn.addEventListener('click', function () {
      form.reset();
 
    });
    form.reset();
  }
  });
});
});
}

2025年12月8日 (月) 18:10時点における版

document.addEventListener('DOMContentLoaded', function () {
  const form = document.getElementById('searchForm');
  if (!form) return;

  // ---- SUBMIT ----
  form.addEventListener('submit', function () {
    const ids = ['searchText','genre','station','budget_min','budget_max'];
    ids.forEach(id => {
      const el = document.getElementById(id);
      if (el && el.value.trim() === '') {
        el.removeAttribute('name');
      }
    });
  });

  // ---- LOAD FROM URL ----
  const params = new URLSearchParams(window.location.search);
  params.forEach((value, key) => {
    document.querySelectorAll(`[name="${key}"]`).forEach(el => {
      if (el.type === "checkbox" || el.type === "radio") {
        if (el.value === value) el.checked = true;
      } else {
        el.value = value;
      }
    });
  });

  // ---- CLEAR BUTTON ----
  const clearBtn = document.querySelector('.clear-btn');
  if (clearBtn) {
    clearBtn.addEventListener('click', function () {
      form.reset();
    });
  }
});