none
SharePoint 2013 - Modal Dialog When Checkbox Value Changes RRS feed

  • Question

  • Hello Community,

    I'm working in SharePoint 2013, with a CEWP and some JQuery.  My goal is to get a Modal Dialog to appear when the user selects a checkbox (whose default value is "No"), but to not appear when the user unchecks the checkbox.  (Basically, by selecting the checkbox, they are setting a field value that will cause the associated workflow to delete the Current Item, Review Task, and Master Task so the modal dialog is a warning message, of course no warning is needed if they uncheck the box.) I can get the Modal Dialog to appear when the check the box, but it also appears when they uncheck the box, and that's the behavior I don't want.  The code is provide below.  Please provide code samples and guidance.

    //Task Delete Change Event
    $(document).ready(function() {  
    $("input[title='Delete Tasks']").change(function() {  
    	
    	//var deleteTasks = $("input[title='Delete Tasks']").val();
    	//alert("value: " + deleteTasks);
    	
    	popup_openModalDialog()	 
    	
    	});  
    });
    
    //Modal Dialogue for Delete Tasks
    function popup_openModalDialog() {
    	
    	//Create HTML Content for Dialogue Box
    	var html = document.createElement('div');
    	html.innerHTML = '<h3>By choosing "Delete Tasks" three items will be deleted: The Current Item, The Related Master Task, and The Review Task. \
    		Click "OK" to Continue and "Cancel" to Reset the "Delete Tasks" field.</h3>\
    		<a href="#" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel); return false;">OK |</a>\
    		<a href="#" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK); return false;"> Cancel</a>';
    	//OK(Cancel)=1, Cancel(Continue)=0
    
    	//Open Dialogue with Set Options
    	OpenPopUpPageWithDialogOptions({
     		title: "NOTICE: Delete Tasks",
     		html:html,
    		width:400,
    		height:100,
     		dialogReturnValueCallback: function(dialogResult){
      		SP.UI.ModalDialog.RefreshPage(dialogResult);
     		}
    	});
    }

    Thanks!

    Tom


    Tom Molskow - Senior SharePoint Architect - Microsoft Community Contributor 2011 and 2012 Award - Linked-In - SharePoint Gypsy

    Tuesday, March 14, 2017 11:38 PM

Answers

  • Hi Tom,

    We need check if the checkbox is checked.

    The code below for your reference:

    <script src="//code.jquery.com/jquery-3.1.0.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(function () { 
    	$("input[title='Delete Tasks']").change(function() {  	
    		//var deleteTasks = $("input[title='Delete Tasks']").val();
    		//alert("value: " + deleteTasks);
    		if($(this).is(':checked')){
    			popup_openModalDialog();
    		}		
    	});  
    });
    //Modal Dialogue for Delete Tasks
    function popup_openModalDialog() {
    	
    	//Create HTML Content for Dialogue Box
    	var html = document.createElement('div');
    	html.innerHTML = '<h3>By choosing "Delete Tasks" three items will be deleted: The Current Item, The Related Master Task, and The Review Task. \
    		Click "OK" to Continue and "Cancel" to Reset the "Delete Tasks" field.</h3>\
    		<a href="#" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.cancel); return false;">OK |</a>\
    		<a href="#" onclick="SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK); return false;"> Cancel</a>';
    	//OK(Cancel)=1, Cancel(Continue)=0
    
    	//Open Dialogue with Set Options
    	OpenPopUpPageWithDialogOptions({
     		title: "NOTICE: Delete Tasks",
     		html:html,
    		width:400,
    		height:100,
     		dialogReturnValueCallback: function(dialogResult){
      		SP.UI.ModalDialog.RefreshPage(dialogResult);
     		}
    	});
    }
    </script>
    

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by Tom Molskow Wednesday, March 15, 2017 3:57 PM
    Wednesday, March 15, 2017 2:09 AM
    Moderator