「Form:店舗/飲食店」の版間の差分
提供: 川西図鑑
その他の操作
編集の要約なし |
編集の要約なし |
||
| 22行目: | 22行目: | ||
| {{{field|郵便番号 | | {{{field|郵便番号 | ||
|input type=regexp | |input type=regexp | ||
|id=zipcode | |||
|placeholder=ハイフンなしの7桁数字で入力してください | |placeholder=ハイフンなしの7桁数字で入力してください | ||
|regexp=/^[0-9]{7}$/ | |regexp=/^[0-9]{7}$/ | ||
| 28行目: | 29行目: | ||
|- | |- | ||
! 住所: | ! 住所: | ||
| {{{field|住所|mandatory}}} | | {{{field|住所|mandatory|id=address}}} | ||
|- | |- | ||
! 営業時間: | ! 営業時間: | ||
| 56行目: | 57行目: | ||
{{{end template}}} | {{{end template}}} | ||
<script> | |||
document.addEventListener("DOMContentLoaded", function () { | |||
const zipInput = document.getElementById("zipcode"); | |||
const addressInput = document.getElementById("address"); | |||
zipInput.addEventListener("input", function () { | |||
// 数字のみ・7桁制限 | |||
const zip = this.value.replace(/[^0-9]/g, "").slice(0, 7); | |||
this.value = zip; | |||
if (zip.length === 7) { | |||
fetch(`https://zipcloud.ibsnet.co.jp/api/search?zipcode=${zip}`) | |||
.then(response => response.json()) | |||
.then(data => { | |||
if (data.results) { | |||
const r = data.results[0]; | |||
// 川西市だけ許可 | |||
if (r.address1 === "兵庫県" && r.address2 === "川西市") { | |||
addressInput.value = r.address1 + r.address2 + r.address3; | |||
} else { | |||
addressInput.value = ""; | |||
alert("兵庫県川西市以外の住所は対象外です。"); | |||
} | |||
} else { | |||
addressInput.value = ""; | |||
alert("該当する住所が見つかりません。"); | |||
} | |||
}) | |||
.catch(err => { | |||
console.error("郵便番号検索エラー:", err); | |||
alert("住所取得に失敗しました。"); | |||
}); | |||
} | |||
}); | |||
}); | |||
</script> | |||
'''自由形式テキスト:''' | '''自由形式テキスト:''' | ||
{{{standard input|free text|rows=10}}} | {{{standard input|free text|rows=10}}} | ||
</includeonly> | </includeonly> | ||
2025年10月24日 (金) 10:48時点における版
これは「店舗/飲食店」フォームです。 このフォームを使用してページを作成するには、下にページ名を入力してください。 その名前のページが既に存在する場合は、そのページを編集するフォームに転送されます。