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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Save button on Quick Create not responding after .preventDefault

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Suggested answer
    Community Member Profile Picture
    on at

    what is arguments[0] ?

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

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

  • Nausher Sayeed Profile Picture
    522 on at

    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
    SrinivasCh Profile Picture
    572 on at

    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
    522 on at

    Hi Srini,

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

    Nausher

  • Rickards08 Profile Picture
    202 on at

    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.

  • Suggested answer
    Philipp Lwn Profile Picture
    on at

    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

  • Emmanuel Barache Profile Picture
    on at

    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

  • hicham Profile Picture
    215 on at

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

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

  • Aminovski Profile Picture
    on at

    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")

    }

  • Suggested answer
    Community Member Profile Picture
    on at

    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");

                               }

                           });

                       }

                   }

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans