/*
* Open/close group fields depending on radio button choice
*
* Licensed under the MIT License
*/(() => {
'use strict';
// Map Radio button to each Field group
const groupMap = {
'Sales Inquiry': 'group_sales',
'Support': 'group_support',
'Partnership': 'group_partnership',
'Other': 'group_other' };
// List of all Field groups
const groupIds = Object.values(groupMap);
// Target events
const eventsSubmit = [
'app.record.detail.show',
'app.record.create.show',
'app.record.edit.show',
'app.record.create.change.radio_button',
'app.record.edit.change.radio_button' ];
kintone.events.on(eventsSubmit, (event) => {
const radioButtonValue = event.record.radio_button.value;
// Close all Field groups first
groupIds.forEach(id => kintone.app.record.setGroupFieldOpen(id, false));
// Open only the field group that matches the Radio button value
const openGroupId = groupMap[radioButtonValue];
if (openGroupId) {
kintone.app.record.setGroupFieldOpen(openGroupId, true);
}
return event;
});
})();