Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Page Validator not working in Webform

Posted on by 105

i m trying to put a page validator to check if there are records in the subgrid. If there is atleast one record in the subgrid it should progress to the next page otherwise it has to throw error. I have implemented a similar code ina different page and it is working fine. but for a different webform step this code isnt working. Can someone please tell me how we can debug a validator. My code is below


$(document).ready(function () {

if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
var newValidator = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "SchoolPlacementvalidator";
newValidator.controltovalidate = "SchoolPlacement";
newValidator.errormessage = "<a href='#SchoolPlacement'>At least one Qualification item must be added to progress.</a>";
newValidator.evaluationfunction = function () {
var SchoolPlacement = $("#SchoolPlacement table tbody tr").length;
if (SchoolPlacement === 0) {
return false
}
else {
return true;
}

};
Page_Validators.push(newValidator);


});

*This post is locked for comments

  • Suggested answer
    Irena Benja Profile Picture
    Irena Benja 412 on at
    RE: Page Validator not working in Webform

    Hi edev,

    Whenever there are no records on a list there is a message showing that can be the default one or some customized from your size.

    Maybe you can work with : contains("no data found"), so finding the presence of a text instead of the table rows.

    Something like this:

     $(".entity-grid.entitylist").on("loaded", function () {
     if($('span:contains("your txt")')){
    //your logic
     }
     });

    Hope it helps!

  • edev Profile Picture
    edev 105 on at
    RE: Page Validator not working in Webform

    Hi Nicholas, yes it is a javascript code and its a jquery call from client side to the script which resides in app server. I have resolved the issue by a temporary fix by disbaling the button until atleast one record is added to the subgrid.

  • Nicholas Hayduk Profile Picture
    Nicholas Hayduk 2,863 on at
    RE: Page Validator not working in Webform

    Sorry, I'm not quite following.

    The code you provided is JavaScript, which means it should run client-side (in the browser).  Where did you add the code to your Portal?  It should be added via the Custom JavaScript field on the Web Form Step.

    Once you have it in the right spot, you should be able to find it in your browser's Developer Tools, and then hopefully by putting a breakpoint there, the breakpoint will be hit when you click the submit button.

    Nick

  • edev Profile Picture
    edev 105 on at
    RE: Page Validator not working in Webform

    Hi Nicholas, it does not give any error and it proceeds to the next page. The problem with my code, we have put the code in app server and calling it in the respective steps and i m not able to debug the code inserting breakpoints. And also i tried to insert an alert and that doesnt work.

  • Nicholas Hayduk Profile Picture
    Nicholas Hayduk 2,863 on at
    RE: Page Validator not working in Webform

    Hi,

    When you say it doesn't work, does it give an error?  Or does it just let you proceed even if there are no rows in the table?

    As Mahender suggested, you'll probably need to use Developer Tools (F12) to get to the bottom of it.  I'd first put a breakpoint on the [if (SchoolPlacement === 0)] line of code, and make sure it is getting there when you click submit, and if it's giving you the value you'd expect.

    Nick

  • edev Profile Picture
    edev 105 on at
    RE: Page Validator not working in Webform

    Hi Mahendar, thanks for responding back. I checked on the console already and it is working fine and giving me the right count.

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Page Validator not working in Webform

    Hi,

    I will suggest you to use chrome Developer tools and first check your code is working fine or not under the console

    $("#SchoolPlacement table tbody tr").length;

    it will help you to troubleshoot.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans