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

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

MediaWikiインターフェイスページ
編集の要約なし
タグ: 差し戻し済み
0rr2f3 (トーク) による版 641 を取り消し
タグ: 取り消し
1行目: 1行目:
document.addEventListener('DOMContentLoaded', function () {
if ( document.querySelector('#searchForm') ) {
   const form = document.getElementById('searchForm');
document.getElementById('searchForm').addEventListener('submit', function (e) {
   if (!form) return;
   const searchText = document.getElementById('searchText');
  const genre = document.getElementById('genre');
  const station = document.getElementById('station');
  const budget_min = document.getElementById('budget_min');
   const budget_max = document.getElementById('budget_max');


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


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


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

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

if ( document.querySelector('#searchForm') ) {
document.getElementById('searchForm').addEventListener('submit', function (e) {
  const searchText = document.getElementById('searchText');
  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 === '') {
    searchText.removeAttribute('name'); // 空のとき name属性を削除
  }
  if (genre.value === '') {
    genre.removeAttribute('name'); // 空のとき name属性を削除
  }
  if (station.value === '') {
    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 () {
  const params = new URLSearchParams(window.location.search);

  params.forEach((value, key) => {
    // input, select, checkbox, radio 全対応
    const el = document.querySelector(`[name="${key}"]`);
    if (!el) return;

    // checkbox / radio (name[] の対応含む)
    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 form     = document.getElementById('searchForm');

  clearBtn.addEventListener('click', function () {

    form.reset();
  });
});

}