How about this:
I have an app with business locations. I need to have a physical address field group and a separate mailing address field group.
I also would like to have a checkbox the user can check if the mailing address is the same as the physical address, that will copy the text from the physical address fields and place those value sin the mailing address fields.
What am I doing wrong here?
(function() {
"use strict";
var MAILINGSAMEASPHYSICAL = 'mailingsameasphysical'; //checkbox field code - Only once checkbox, "Yes"
var PSTREETNUMBER = 'physicaladdressstreetnumber'; //Physical Address Street Number field code
var MSTREETNUMBER = 'mailingaddressstreetnumber'; //Mailing Address Street Number field code
//Skipping the other fields for berevity
//Event types that trigger the script when the checkbox is checked
//Not when the user saves the form, but when they check the checkbox
var events = ["app.record.create.change." + MAILINGSAMEASPHYSICAL, "app.record.edit.change." + MAILINGSAMEASPHYSICAL];
kintone.events.on(events, function(event) {
var record = event.record;
var mailingSameVal = record[MAILINGSAMEASPHYSICAL].value; //Get the value of the checkboxes
var pStreetNumberStr = record.physicaladdressstreetnumber.value; //Value of the physical address street number
var mStreetNumberStr = record.mailingaddressstreetnumber.value; //Value of the mailing address street number
//Skipping the other field for berevity
if (mailingSameVal.indexOf('Yes') >= 0) { //If the value of the Yes checkbox >= 0
mStreetNumberStr = pStreetNumberStr; //Take the value of the physical address street number and copy it into the value of the mailin gaddress street number
//Skipping the other field for berevity
} else { //If the value of the yes checkbox is not changed to >= 0
mStreetNumberStr = null; //Make the value of the mailing address street number blank
//Skipping the other field for berevity
}
return event;
});
}());