Last active
August 29, 2015 14:04
-
-
Save fddcddhdd/429e7a81f0b90de0bb03 to your computer and use it in GitHub Desktop.
郵便番号→住所 for kintone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
"use strict"; | |
//チェックボックス変更時のイベント | |
kintone.events.on(["app.record.create.change.address_trans", "app.record.edit.change.address_trans"],function(event){ | |
var record = event.record; | |
var zipcode = record.zipcode.value; | |
//住所変換のチェック | |
if(record.address_trans.value == '住所変換'){ | |
//jQuery ajaxで同期処理 | |
$.ajax({ | |
url:'http://api.aoikujira.com/zip/json/' + zipcode, | |
dataType:'json', | |
async:false, | |
success:function(json){ | |
// 都道府県が取得出来なかったら、該当なしと判定する(エラー発生せずにjsonが返ってくる) | |
if(json.state == ""){ | |
alert('該当なし'); | |
}else{ | |
event.record.address_kana.value = json.ken_kana + json.city_kana + json.address_kana; | |
event.record.address.value = json.state + json.city + json.city + json.address; | |
} | |
} | |
}); | |
//住所変換のチェックを外されたら | |
}else{ | |
event.record.address.value = ''; | |
event.record.address_kana.value = ''; | |
} | |
return event; | |
}); | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment