web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

In Portal entity form on submit form Page_Validators facing error.

(0) ShareShare
ReportReport
Posted on by

Hi All,

Please help below code.

if (window.jQuery) {
(function ($) {
$(document).ready(function () {
debugger;
if (typeof (Page_Validators) == 'undefined') return;
// Create new validator
var newValidator1 = document.createElement('span');
newValidator.style.display = "none";
newValidator.id = "new_facebookurlValidator";
newValidator.controltovalidate = "new_facebookurl";
newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form
newValidator.initialvalue = "";
newValidator.evaluationfunction = function () {
$('#UpdateButton').change(function () {
var fbresult = $("#new_doyouhavefacebook").val();
alert(fbresult);
if (fbresult == 260760000)//Yes
{
newValidator.errormessage = "<a href='#new_facebookurl_label'> FaceBook URL is required.</a>";
}
else if (fbresult == 260760001)//No
{
return false;
}
else if (fbresult == "")//Null
{
return false;
}
});
};
// Add the new validator to the page validators array:
Page_Validators.push(newValidator);

// Wire-up the click event handler of the validation summary link
$("a[href='#new_facebookurl_label']").on("click", function () { scrollToAndFocus('new_facebookurl_label', 'new_facebookurl'); });
});
}(window.jQuery));
}

for above code If Field value is YES, then it's through FB URL is required.

but even no value or field value is NO, on submission getting below error

1538.Capture.JPG

*This post is locked for comments

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: In Portal entity form on submit form Page_Validators facing error.

    This doesn't seem correct :(.

    Can you try this and see if it helps. Basically you need to return true/false for each of your condition and do not use the #updatebutton.change statement. Please ensure that you clear server cache after the changes otherwise portal will load the old scripts.

    =================

    if (window.jQuery) {

       (function ($) {

           $(document).ready(function () {

               debugger;

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

               // Create new validator

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

               newValidator.style.display = "none";

               newValidator.id = "new_facebookurlValidator";

               newValidator.controltovalidate = "new_facebookurl";

               newValidator.validationGroup = ""; // Set this if you have set ValidationGroup on the form

               newValidator.initialvalue = "";

               newValidator.evaluationfunction = function () {

                   var fbresult = $("#new_doyouhavefacebook").val();

                   alert(fbresult);

                   if (fbresult == 260760000)//Yes

                   {

                       newValidator.errormessage = "<a href='#new_facebookurl_label'> FaceBook URL is required.</a>";

                       return true;

                   }

                   else if (fbresult == 260760001)//No

                   {

                       return false;

                   }

                   else if (fbresult == "")//Null

                   {

                       return false;

                   }

               });

           // Add the new validator to the page validators array:

           Page_Validators.push(newValidator);

           // Wire-up the click event handler of the validation summary link

           $("a[href='#new_facebookurl_label']").on("click", function () { scrollToAndFocus('new_facebookurl_label', 'new_facebookurl'); });

       });

    } (window.jQuery));

    }

    =================

    Hope this helps.

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: In Portal entity form on submit form Page_Validators facing error.

    Hi Chandhu,

    How did you get on with this? If you have got your answer then please close the thread by marking the suggestion as verified.

  • Community Member Profile Picture
    on at
    RE: In Portal entity form on submit form Page_Validators facing error.

    Hi Ravi,

    Sorry it's not working.

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: In Portal entity form on submit form Page_Validators facing error.

    Can you please share what is happening (or not working)? I have verified the above code in my test portal and its working fine.

  • Community Member Profile Picture
    on at
    RE: In Portal entity form on submit form Page_Validators facing error.

    Hi Ravi,

    Instated of your code, i used below code, it's completely different.

    // Custom validation

    if (typeof (entityFormClientValidate) != 'undefined') {

       var originalValidationFunction = entityFormClientValidate;

       if (originalValidationFunction && typeof (originalValidationFunction) == "function") {

           entityFormClientValidate = function () {

               originalValidationFunction.apply(this, arguments);

               // Remove previous custom validation messages & hide validation container

               if ($('.validation-summary').length > 0) {

                   $('.validation-summary').empty();

                   $('.validation-summary').attr('style', 'display:none;');

               }

               var errMsgHTML = '';

               // Fields to validate

               var $elFldvalidate3 = $('#new_facebookurl');

               var $elFldvalidate4 = $('#new_instagramurl');

               var $elFldvalidate5 = $('#new_twitterurl');

               var $elFldvalidate6 = $('#new_linkedinurl');

               // Validation rules:

               var rule3 = (($elFldvalidate3.closest('tr').find('.info').hasClass('required')) && ($elFldvalidate3.val() === ''));

               var rule4 = (($elFldvalidate4.closest('tr').find('.info').hasClass('required')) && ($elFldvalidate4.val() === ''));

               var rule5 = (($elFldvalidate5.closest('tr').find('.info').hasClass('required')) && ($elFldvalidate5.val() === ''));

               var rule6 = (($elFldvalidate6.closest('tr').find('.info').hasClass('required')) && ($elFldvalidate6.val() === ''));

               var ruleSet = (rule3 | rule4 | rule5 | rule6);

               // Handle validation

               if (ruleSet) {

                   errMsgHTML = '<div id="fsbgm_custom-validation">' +

                       '<h2 class="validation-header"><span role="presentation" class="fa fa-info-circle"></span> ' +

                       'The form could not be submitted for the following reasons:</h2><ul><li>' +

                       '<a href="#" onclick="javascript:$("html, body").animate({scrollTop: $("#gm_vendor_name' +

                       '").offset().top}, 2000);return false;">Please fill out all required fields denoted with "*".</a></li></ul></div>';

                   // Append message to validation summary element and display

                   $('.validation-summary').append(errMsgHTML).removeAttr('style');

                   $('html, body').animate({

                       scrollTop: $('.validation-summary').offset().top

                   }, 2000);

                   return false;

               } else {

                   // Form is valid

                   return true;

               }

           };

       }

    }

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: In Portal entity form on submit form Page_Validators facing error.

    Okay..So wIs it working or not working? If not working then did you check browser console for any errors? If it is not working and if you still need to find why then I would suggest to break your script into smaller chukc and see if that works. It is hard to debug/review the full script.

  • Community Member Profile Picture
    on at
    RE: In Portal entity form on submit form Page_Validators facing error.

    Hi Ravi,

    at the time of starting my code is wrong logic, after forward your code, i am facing issue is "clear server cache after the changes otherwise portal will load the old scripts"

    your code also working, this one also working, for 4 fields at a time for reducing of code i implemented with above code.

    Thanks for your help Ravi.

    Thanks

    CM Y

  • RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: In Portal entity form on submit form Page_Validators facing error.

    Great.. Glad I could help :)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
UllrSki Profile Picture

UllrSki 2

#1
Community Member Profile Picture

Community Member 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans