Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Save button on Quick Create not responding after .preventDefault

Posted on by 5

Hi, I'm running the code below on the save of a quick create form (and passing in context).  When there are no errors it runs and saves fine.  When an error is encountered it prevents the save as it should and displays error messages in the validateXX functions.  The problem is once I clear up the errors the save button will not function.  The mouseover works, but it does not respond to the click.  What I did notice is the little blue dots at the top of the quick create continue to cycle like the page is loading.  Thoughts or hints?

function form_OnSave()
{
var errorCount = 0;
var activityType = Xrm.Page.getAttribute("ocsd_k9activitytype").getValue();

if (activityType == null)
{
alert("Something went wrong, there is not activity type for this record, please contact Systems");
arguments[0].getEventArgs().preventDefault();

}

if (activityType == 868030004) //training scenario validation
{
errorCount = validateScenario() + validateMeasurement() + validateTraining() + validatePassFail() + validateAmountQty();
}
else
{
errorCount = validateAmountQty() + validateField() + validateMeasurement();
}
if (errorCount != 0) {
arguments[0].getEventArgs().preventDefault();

}
}

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save button on Quick Create not responding after .preventDefault

    This is what is working for me...

    onSaveHandler = function (context) {

                       var saveButton = null;

                       var getAttribute = function() {

                           var attribute = saveButton.getAttribute("disabled");

                           // Check that the attribute is ready

                           if (attribute == null) {

                               setTimeout(getAttribute, 2000);

                               return;

                           }

                           saveButton.removeAttribute("disabled");

                       };

                       var enableSaveButton = function () {

                           var buttonName = "globalquickcreate_save_button_NavBarGloablQuickCreate";

                           saveButton = parent.document.getElementById(buttonName);

                           if (!saveButton) {

                               saveButton = top.document.getElementById(buttonName);

                           }

                           // Check that the element is ready

                           if (saveButton == null) {

                               setTimeout(enableSaveButton, 1000);

                               return;

                           }

                           getAttribute();

                       };

                       if (!isAddressValidated) {

                           context.getEventArgs().preventDefault();

                           // Enable save button

                           enableSaveButton();

                           addressValidation().done(function(result) {

                               if (result) {

                                   isAddressValidated = true;

                                   Xrm.Page.data.entity.save("saveandclose");

                               }

                           });

                       }

                   }

  • Aminovski Profile Picture
    Aminovski on at
    RE: Save button on Quick Create not responding after .preventDefault

    Thank you Hicham for your answer. I've tried this code but I had 2 issues with that:

    - The Quick Create form is in an iFrame, so you have to go to the parent node to get the button element.

    - You cannot get an element by a simple getElementById or something else equivalent in jQuery as long as it is not supported. This returns null at each time.

    I've tried then this code which was inspired from yours and it does work fine for me. You just have to call enableSaveButton() function just after PreventDefault.

    var saveButton = null;

    function enableSaveButton() {

       saveButton = parent.document.getElementById('globalquickcreate_save_button_NavBarGloablQuickCreate');

       // Check that the element is ready

       if (saveButton == null) {

           setTimeout('enableSaveButton()', 2000);

           return;

       }

       getAttribute();

    }

    function getAttribute() {

       var attribute = saveButton.getAttribute("disabled");

       // Check that the attribute is ready

       if (attribute == null) {

           setTimeout('getAttribute()', 2000);

           return;

       }

       saveButton.removeAttribute("disabled")

    }

  • hicham Profile Picture
    hicham 215 on at
    RE: Save button on Quick Create not responding after .preventDefault

    you can renable the button with this like of code just after PreventDefault:

    $('#globalquickcreate_save_button_NavBarGloablQuickCreate').prop('disabled',false);

  • RE: Save button on Quick Create not responding after .preventDefault

    Hi there,

    We are April 5 2017, working with Dynamics CRM 365 and I can see that this issue is still alive :

    Using this method with a quick form, save button is disable and the form need to be posted with Crtrl+S !

    Actually, I can see that there is no hurry for Microsoft to address this issue !

    Does anyone experimented a solution or workaround for this issue ?

    Thanks for the feedback,

    Emmanuel Barache

    CRM Consultant

    NOVULYS

  • Suggested answer
    Philipp Lwn Profile Picture
    Philipp Lwn on at
    RE: Save button on Quick Create not responding after .preventDefault

    Hello, 

    I have the same problem CRM 2016 on-prem and SP1. The save button remains disabled.

    But you can still save the form with Ctrl+S

    Ref: https://community.dynamics.com/crm/f/117/t/191954

    Hi casualties ;)

    I have the same issue. The Save button stops working after preventDefault() call (but Crtl + S continue working). I think it's a bug from Microsoft.

    Did you find a solution, or any workaround?

    Regatds,

    FV

  • Rickards08 Profile Picture
    Rickards08 200 on at
    RE: Save button on Quick Create not responding after .preventDefault

    I'm experiencing the same issue. Progress "balls" are moving and I'm not able to trigger the save event again by clicking the save button. Never seen this issue on normal forms before. 

    Looking at the HTML of the save button i can see that the preventDefault() function actually added an disabled="disabled" attribute to the save button html. So most likely a bug.

  • Nausher Sayeed Profile Picture
    Nausher Sayeed 520 on at
    RE: Save button on Quick Create not responding after .preventDefault

    Hi Srini,

    After execute of context.getEventArgs().preventDefault(), i am not able to save the record again from quick create form

    Nausher

  • Suggested answer
    SrinivasCh Profile Picture
    SrinivasCh 572 on at
    RE: Save button on Quick Create not responding after .preventDefault

    Hi David,

    I am suspecting about initialization of arguments[0] .

    for onsave method executioncontext is automatically passed.

    here arguments[0] should be executioncontext.

    Hope this helps!!

    Srini Ch

    Mark As Answer ,if you get answer of your question :)

  • Nausher Sayeed Profile Picture
    Nausher Sayeed 520 on at
    RE: Save button on Quick Create not responding after .preventDefault

    I am gettng the same issue.
    I believe i have the same issue occurring. I also notice after the preventdefault the blue dots at the top of the form usually indicating that the form is loading.
    I believe this is microsofot bug.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Save button on Quick Create not responding after .preventDefault

    what is arguments[0] ?

    Please refer the below link for using preventdefault in correct way :

    msdn.microsoft.com/.../gg509060.aspx

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