Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Check at least once check box is selected in a section in D365 portal

(0) ShareShare
ReportReport
Posted on by

Hi All,

I'm trying to implement a business logic where I need to check at least one check box selected in a section in D365 portal. 

Could you please let me know if this possible to get all check boxes value dynamically in a section. If yes, please share the syntax/code. 

Regards,

Leo 

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at
    RE: Check at least once check box is selected in a section in D365 portal

    Hi LeoFernandas,

    You should add a double check in each check box event

    $("#mxr_hololens1").change(function () {
                    debugger;
        if (this.checked) {
            if (($('#mxr_hololens1').is(':checked')) || ($('#mxr_hololens2').is(':checked')) || ($('#mxr_wmr').is(':checked')) || ($('#mxr_pc').is(':checked')) || ($('#mxr_ios').is(':checked')) || ($('#mxr_android').is(':checked'))){
                removeValidator('mxr_hololens1');
            }
                        
        }
     });

    Thanks
    Justin Jose

  • LeoFernandas Profile Picture
    on at
    RE: Check at least once check box is selected in a section in D365 portal

    I'm able to take care of the error message part but couldn't do the other validation.

    Thank you very much for talking time to answer all my questions, Justin! :)

  • LeoFernandas Profile Picture
    on at
    RE: Check at least once check box is selected in a section in D365 portal

    Thanks alot, Justin! :) I've verified your answer.   

    When I tried after adding remove validation on other control, it works as expected. But one thing I have noticed is, for an instance, I select a checkbox, unselect it just before submitting the form, then it allows the form submission while it shouldn't happen so.

    Also, I would like modify the error message pops up while condition doesn't meet. Currently, is says as "mxr_hololens1 Please select at least one value from What type of device does your application run on?." wherein I feel that it should be good if schema name of the field can be removed from here but it should have the hyperlink in the error message.

    pastedimage1587554381948v1.png

    Could you help me out here please?

    Best Regards,

    Leo

  • Verified answer
    Justinjose Profile Picture
    2,707 on at
    RE: Check at least once check box is selected in a section in D365 portal

    Hi LeoFernandas,

    You should remove validation object on other button click.

    // Section1 check box list onchange
                $("#mxr_hololens1").change(function () {
                    debugger;
                    if (this.checked) {
                        removeValidator('mxr_hololens1');
                    }
                }); 
                
                 $("#mxr_hololens2").change(function () {
                    debugger;
                    if (this.checked) {
                        removeValidator('mxr_hololens1');
                    }
                }); 
                
                 $("#mxr_wmr").change(function () {
                    debugger;
                    if (this.checked) {
                        removeValidator('mxr_hololens1');
                    }
                }); 
                
                 $("#mxr_pc").change(function () {
                    debugger;
                    if (this.checked) {
                        removeValidator('mxr_hololens1');
                    }
                }); 
                
                $("#mxr_ios").change(function () {
                    debugger;
                    if (this.checked) {
                        removeValidator('mxr_hololens1');
                    }
                }); 
                
                $("#mxr_android").change(function () {
                    debugger;
                    if (this.checked) {
                        removeValidator('mxr_hololens1');
                    }
                }); 
                
     

    For each section you should pass a unique value to the AddValidion function and should remove this when any of the section button meets requirement.

    Thanks
    Justin Jose

  • LeoFernandas Profile Picture
    on at
    RE: Check at least once check box is selected in a section in D365 portal

    Hi Justin,

    I have added all check boxes schema name in if condition and passed only one check box value to addValidator function. Here, i can see that the form submission is stopped when no check box is selected. However, when i tried selecting other check box from the section and submitting form, it didn't allow me to submit until I select the check box which is passed to addValidator method. 

    Could you guide me please?

    $(document).ready(function () {
            debugger;
            if ((!$('#mxr_hololens1').is(':checked')) && (!$('#mxr_hololens2').is(':checked')) && (!$('#mxr_wmr').is(':checked')) && (!$('#mxr_pc').is(':checked')) && (!$('#mxr_ios').is(':checked')) && (!$('#mxr_android').is(':checked'))){
                addValidator('mxr_hololens1', 'mxr_hololens1');
            }
    
            function addValidator(fieldName, fieldLabel) {
                debugger;
                if (typeof (Page_Validators) == undefined) return;
                var newValidator = document.createElement('span');
                newValidator.style.display = "none";
                newValidator.id = fieldName   "Validator";
                newValidator.controltovalidate = fieldName;
                newValidator.errormessage = ""   fieldLabel   " Please select at least one value fom What type of device does your applicatoin run on?.";
                newValidator.validationGroup = "";
                newValidator.initialvalue = "";
                newValidator.evaluationfunction = function () {           
                    var value = $("#"   fieldName).is(":checked");            
                    if (value) {
                        return true;
                    } else {
                        return false;
                    }
                };
    
                Page_Validators.push(newValidator);
                
                function removeValidator(fieldName) {
                    Page_Validators = $.grep(Page_Validators, function (item) {
                        return item.id !== fieldName   "Validator";
                    });
                }
                // Section1 check box list onchange
                $("#mxr_hololens1").change(function () {
                    debugger;
                    if (this.checked) {
                        removeValidator('mxr_hololens1');
                    }
                }); 
            }
        });

    Regards,

    Leo

  • LeoFernandas Profile Picture
    on at
    RE: Check at least once check box is selected in a section in D365 portal

    Hi Justin,

    Thank you very much for this work around. Yes, I did try this out and it works quite well for single check box field. 

    Could you please help me how to check whether at least one check box is selected in one section and stop form submission if no check box is selected. 

    Regards,

    Leo

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at
    RE: Check at least once check box is selected in a section in D365 portal

    Hi LeoFernandas,

    Could you try the below code.

    $(document).ready(function () {
            debugger;
            // Section 1 checkbox list
            if (!$('#mxr_inwindowsstore').is(':checked')) {
                addValidator('mxr_inwindowsstore', 'mxr_inwindowsstore');
            }
    
            function addValidator(fieldName, fieldLabel) {
                debugger;
                if (typeof (Page_Validators) == undefined) return;
                var newValidator = document.createElement('span');
                newValidator.style.display = "none";
                newValidator.id = fieldName   "Validator";
                newValidator.controltovalidate = fieldName;
                newValidator.errormessage = ""   fieldLabel   " not checked.";
                newValidator.validationGroup = "";
                newValidator.initialvalue = "";
                newValidator.evaluationfunction = function () {           
                    var value = $("#"   fieldName).is(":checked");            
                    if (value) {
                        return true;
                    } else {
                        return false;
                    }
                };
    
                Page_Validators.push(newValidator);
                
                function removeValidator(fieldName) {
                    Page_Validators = $.grep(Page_Validators, function (item) {
                        return item.id !== fieldName   "Validator";
                    });
                }
                // Section1 check box list onchange
                $("#mxr_inwindowsstore").change(function () {
                    debugger;
                    if (this.checked) {
                        removeValidator('mxr_inwindowsstore');
                    }
                });
            }
        });

    Thanks
    Justin Jose

  • LeoFernandas Profile Picture
    on at
    RE: Check at least once check box is selected in a section in D365 portal

    Hi Justin,

    Thank you for this workaround. I tried to check this out for one check box initially by updating your code, but the expected result was coming as it allows me to submit the form though I didn't that particular check box. When I debug the code, the control was going to the line high lighted in yellow, and then I pressed F10, then the control was transferred directly to next high lighted line in yellow and then it comes out as I again pressed F10. 

    $(document).ready(function () {

       // Section 1 checkbox list

       if ((!$('#mxr_inwindowsstore').is(':checked'))) {

           addValidator('mxr_inwindowsstore', 'mxr_inwindowsstore_label');

    }

       function addValidator(fieldName, fieldLabel) {

           debugger;

           if (typeof (Page_Validators) == undefined) return;

           var newValidator = document.createElement('span');

           newValidator.style.display = "none";

           newValidator.id = fieldName + "Validator";

           newValidator.controltovalidate = fieldName;

           newValidator.errormessage = "<a href='#" + fieldName + "_label'>" + fieldLabel + " not checked.</a>";

           newValidator.validationGroup = "";

           newValidator.initialvalue = "";

           newValidator.evaluationfunction = function () {

              // var value = $("#" + fieldName).val();

    var value = $("#" + fieldName).is(":checked");

              // if (value == null || value == "")

      if(value == false){

                   return true;

               } else {

                   return false;

               }

           };

           function removeValidator(fieldName) {

               Page_Validators = $.grep(Page_Validators, function (item) {

                   return item.id !== fieldName + "Validator";

               });

           }

           // Section1 check box list onchange

           $("#mxr_inwindowsstore").change(function () {

               debugger;

               if (this.checked) {

                   removeValidator('mxr_inwindowsstore');

               }

           });

       }

    });

    Could you please tell me help me here?

    Regards,

    Leo

  • Suggested answer
    Justinjose Profile Picture
    2,707 on at
    RE: Check at least once check box is selected in a section in D365 portal

    Hi LeoFernandas,

    Here is the pseudocode.

    $(document).ready(function () {
        // Section 1 checkbox list
        if ((!$('#CheckBoxId1').is(':checked')) && (!$('#CheckBoxId2').is(':checked')) && (!$('#CheckBoxId3').is(':checked'))) {
            addValidator('section1', "section1");
        }
    
        // Section 2 checkbox list
        if (!($('#CheckBoxId1').is(':checked')) && (!$('#CheckBoxId2').is(':checked')) && (!$('#CheckBoxId3').is(':checked'))) {
            addValidator('section2', "section1");
        }
    
    
        function addValidator(fieldName, fieldLabel) {
    
            if (typeof (Page_Validators) == 'undefined') return;
            var newValidator = document.createElement('span');
            newValidator.style.display = "none";
            newValidator.id = fieldName   "Validator";
            newValidator.controltovalidate = fieldName;
            newValidator.errormessage = ""   fieldLabel   " not checked.";
            newValidator.validationGroup = "";
            newValidator.initialvalue = "";
            newValidator.evaluationfunction = function () {
                var value = $("#"   fieldName).val();
                if (value === null || value === "") {
                    return false;
                } else {
                    return true;
                }
            };
    
            function removeValidator(fieldName) {
                Page_Validators = $.grep(Page_Validators, function (item) {
                    return item.id !== fieldName   "Validator";
                });
    
            }
    
            // Optional. If there is Yes or No check 
            // if ($('#CheckBoxId1').is(':checked') && Page_Validators.filter(e => e.id === fieldName   'Validator').length === 0) {
            //     Page_Validators.push(newValidator);
            // }
    
            // Section1 check box list onchange
            $("#CheckBoxId1").change(function () {
                debugger;
                if (this.checked) {
                    removeValidator("section1");
                }
            });
    
            $("#CheckBoxId2").change(function () {
                debugger;
                if (this.checked) {
                    removeValidator("section1");
                }
            });
    
    
            // Section2 check box list onchange
            $("#CheckBoxId1").change(function () {
                debugger;
                if (this.checked) {
                    removeValidator("section2");
                }
            });
    
            $("#CheckBoxId2").change(function () {
                debugger;
                if (this.checked) {
                    removeValidator("section2");
                }
            });
        }
    });

    If there is Yes or No Check box then you should add newValidator object to  Page_Validators.push(newValidator);

    For more information - https://docs.microsoft.com/en-us/powerapps/maker/portals/configure/add-custom-javascript

    Thanks
    Justin Jose

  • LeoFernandas Profile Picture
    on at
    RE: Check at least once check box is selected in a section in D365 portal

    Hi Justin,

    Thank you for this workaround. I would like to check this out on submit of a form as well. Ideally this validation should happen on form submission and it should restrict the user from submitting the form when no check box is checked.

    Regards,

    Leo

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans