都道府県・市区町村はドロップダウンから、町名番地は文字列に手入力を行ってもらい、最終的にひとつの文字列フィールドにデータをコピーして結合したいと考えています。
都道府県、市区町村は選択項目により表示するフィールドを絞りたいので、下記ページを参考に作成しました。
https://qiita.com/RyBB/items/d133cad3be1346573945
(function() {
'use strict';
var events = [
'app.record.create.show',
'app.record.edit.show',
'app.record.create.change.都道府県',
'app.record.edit.change.都道府県',
'app.record.create.change.大阪府市区町村',
'app.record.edit.change.大阪府市区町村',
'app.record.create.change.兵庫家市区町村',
'app.record.edit.change.兵庫県市区町村',
'app.record.create.change.奈良県市区町村',
'app.record.edit.change.奈良県市区町村',
'app.record.create.change.京都府市区町村',
'app.record.edit.change.京都府市区町村',
'app.record.create.change.町名番地',
'app.record.edit.change.町名番地',
'app.record.detail.show',
];
kintone.events.on(events, function(event) {
// 初期値としてフィールドを隠す
kintone.app.record.setFieldShown('大阪府市区町村', false);
kintone.app.record.setFieldShown('兵庫県市区町村', false);
kintone.app.record.setFieldShown('奈良県市区町村', false);
kintone.app.record.setFieldShown('京都府市区町村', false);
kintone.app.record.setFieldShown('町名番地', false);
// 選択フィールドの値を取得
var RadioVal = event.record['都道府県'].value;
// 選択肢により表示プルダウンを変更
switch (RadioVal) {
case '大阪府' :
kintone.app.record.setFieldShown('大阪府市区町村', true);
kintone.app.record.setFieldShown('町名番地', true);
break;
case '兵庫県' :
kintone.app.record.setFieldShown('兵庫県市区町村', true);
kintone.app.record.setFieldShown('町名番地', true);
break;
case '奈良県' :
kintone.app.record.setFieldShown('奈良県市区町村', true);
kintone.app.record.setFieldShown('町名番地', true);
break;
case '京都府' :
kintone.app.record.setFieldShown('京都府市区町村', true);
kintone.app.record.setFieldShown('町名番地', true);
break;
}
});
})();
このコードは問題なく動作しています。
ここに、都道府県で大阪府が選択された場合は、住所フィールド(文字列)に「都道府県(ドロップダウン) + 大阪府市区町村(ドロップダウン) + 番地町名(文字列)」を表示させたいのですが、上手くできません…。
どういったコードの記載・追加を行えばいいか、ご指導頂ければ幸いです。
宜しくお願い致します。
yyy さん
こんにちは!
値を書き換える場合は event を return で返してあげる必要があります。
以下、記述例です。参考になれば幸いです!
(function() {
'use strict';
var events = [
'app.record.create.show',
'app.record.edit.show',
'app.record.create.change.都道府県',
'app.record.edit.change.都道府県',
'app.record.create.change.大阪府市区町村',
'app.record.edit.change.大阪府市区町村',
'app.record.create.change.兵庫家市区町村',
'app.record.edit.change.兵庫県市区町村',
'app.record.create.change.奈良県市区町村',
'app.record.edit.change.奈良県市区町村',
'app.record.create.change.京都府市区町村',
'app.record.edit.change.京都府市区町村',
'app.record.create.change.町名番地',
'app.record.edit.change.町名番地',
'app.record.detail.show',
];
kintone.events.on(events, function(event) {
// 初期値としてフィールドを隠す
kintone.app.record.setFieldShown('大阪府市区町村', false);
kintone.app.record.setFieldShown('兵庫県市区町村', false);
kintone.app.record.setFieldShown('奈良県市区町村', false);
kintone.app.record.setFieldShown('京都府市区町村', false);
kintone.app.record.setFieldShown('町名番地', false);
// 選択フィールドの値を取得
var RadioVal = event.record['都道府県'].value;
// 選択肢により表示プルダウンを変更
switch (RadioVal) {
case '大阪府' :
kintone.app.record.setFieldShown('大阪府市区町村', true);
kintone.app.record.setFieldShown('町名番地', true);
event.record['住所'].value = RadioVal + event.record['大阪府市区町村'].value;
break;
case '兵庫県' :
kintone.app.record.setFieldShown('兵庫県市区町村', true);
kintone.app.record.setFieldShown('町名番地', true);
event.record['住所'].value = RadioVal + event.record['兵庫県市区町村'].value;
break;
case '奈良県' :
kintone.app.record.setFieldShown('奈良県市区町村', true);
kintone.app.record.setFieldShown('町名番地', true);
event.record['住所'].value = RadioVal + event.record['奈良県市区町村'].value;
break;
case '京都府' :
kintone.app.record.setFieldShown('京都府市区町村', true);
kintone.app.record.setFieldShown('町名番地', true);
event.record['住所'].value = RadioVal + event.record['京都府市区町村'].value;
break;
}
return event;
});
})();
文系男さん
return忘れ…初歩的なミスでお恥ずかしい限りです、、、
アドバイス、記述例本当にありがとうございます!
無事に動作させることができました!!
system
(system)
クローズされました:
5
このトピックはベストアンサーに選ばれた返信から 3 日が経過したので自動的にクローズされました。新たに返信することはできません。