/*

Owner: Demand Solutions Group
Copyright (c) 2006, Demand Solutions Group
All rights reserved.


Agreement

Redistribution and use of this software in source and binary forms, with or 
without modification, are permitted provided that all of the following 
conditions are met:

(1) Redistributions of source code must retain:
	(i) the above copyright notice,
 	(ii) this list of redistribution conditions, and 
 	(iii) the disclaimer appearing below.

(2) Redistributions in binary form must retain: 
	(i) the above copyright notice, 
	(ii) this list of redistribution conditions, and 
	(iii) the disclaimer appearing below in the documentation and/or any other 
	materials provided with the distribution.
	
(3)	Neither the name of the Demand Solutions Group nor the names of its 
	contributors may be used to endorse or promote products derived from this 
	software without specific prior written permission. 

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

*/

/*  
Name of Script – radio_buttons.js 


Date of Script
	Creation or Modification


Version


Type of Script
1.	Client, Server – client 
2.	Sub-Type of script – validation, workflow, business logic, calculation… - validation    


Categories (For searching)
1.	Radio buttons
2.	Checkboxes acting as radio buttons


Description – Because NetSuite currently does not have the functionality to create radio buttons, this script forces checkboxes to function as radio buttons. This means only one checkbox out of a group can be checked at a time, as opposed to multiple checkboxes being checked. 


Business Problem Being Solved – Forcing the user to select only one option out of a group of checkboxes.


Usage Documentation


Installation Instructions – 
1.	Make sure custom code is enabled under Setup > Company > Enable Features.
2.	Edit the radio_button.js file so that the field names match your field names.
3.	Upload radio_button.js to the SuiteScript folder in the file cabinet. 
4.	Edit the form you want to have the checkboxes function as radio buttons.
5.	On the Custom Code tab select the radio_buttons.js file.
6.	In the Field Changed Function field enter the function name (fieldChangeFunc).


Requirements & Preconditions necessary for script to function properly
1.	Version of NetSuite – Any version with custom code enabled.

2.	Customization Prerequisites – all custom checkbox fields are created and custom code is enabled
 
*/





// START FIELD CHANGED FUNCTION ====================================
function fieldChangeFunc(type, fld)
{
	var checkboxName;
	
	// as each checkbox changes grab the new value and if the new value is true set other checkboxes to false	
	if(fld == 'custentity_checkbox1')
	{
		checkboxName = nlapiGetFieldValue('custentity_checkbox1');		
		if(checkboxName == 'T')
		{
			nlapiSetFieldValue('custentity_checkbox2', 'F');
			nlapiSetFieldValue('custentity_checkbox3', 'F');
			nlapiSetFieldValue('custentity_checkbox4', 'F');
		}
	}
	
	if(fld == 'custentity_checkbox2')
	{
		checkboxName = nlapiGetFieldValue('custentity_checkbox2');		
		if(checkboxName == 'T')
		{
			nlapiSetFieldValue('custentity_checkbox1', 'F');
			nlapiSetFieldValue('custentity_checkbox3', 'F');
			nlapiSetFieldValue('custentity_checkbox4', 'F');
		}
	}
	
	if(fld == 'custentity_checkbox3')
	{
		checkboxName = nlapiGetFieldValue('custentity_checkbox3');		
		if(checkboxName == 'T')
		{
			nlapiSetFieldValue('custentity_checkbox2', 'F');
			nlapiSetFieldValue('custentity_checkbox1', 'F');
			nlapiSetFieldValue('custentity_checkbox4', 'F');
		}
	}
	
	if(fld == 'custentity_checkbox4')
	{
		checkboxName = nlapiGetFieldValue('custentity_checkbox4');		
		if(checkboxName == 'T')
		{
			nlapiSetFieldValue('custentity_checkbox2', 'F');
			nlapiSetFieldValue('custentity_checkbox3', 'F');
			nlapiSetFieldValue('custentity_checkbox1', 'F');
		}
	}
	
	
}
// END FIELD CHANGED FUNCTION ======================================



     
