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)

Javascript, onChange events no longer work on an empty field

(0) ShareShare
ReportReport
Posted on by 3,755

I just noticed that if you have a form field that triggers a Javascript function on the onChange event it no longer triggers the function if you clear the field, but ONLY when you change the field data. For instance; if you have a Name field populated with a name, and you remove the name - the function isn't triggered. It's left empty. You have to change the text inside the field.

Is this a bug? Please don't tell me this feature was removed? It was incredibly useful.

*This post is locked for comments

I have the same question (0)
  • DlwK Profile Picture
    607 on at

    I am having the same issue as described in the problem description.

    This is my code that is on the OnChange event of the field languageid

    function LanguageChanged()

    {

    var page = Xrm.Page;

    if (page == null) return;

    page.getAttribute("languageid").setSubmitMode("always");

    page.getAttribute("titleid").setSubmitMode("always");

    var obj = page.getAttribute("languageid");

    if  (obj.getValue() == null)

    {

    page.getControl("titleid").setDisabled(true);

    page.getAttribute("titleid").setValue(null);

           page.getAttribute("titleid").setRequired("none");

    }

    else

    {

    page.getControl("titleid").setDisabled(false);

           page.getAttribute("titleid").setRequired("required");

    }

    }

    I think it is caused because this languageid field is required. If I clear it I get a warning that the field is blank, but the OnChange trigger is not fired.

  • Rodrigo Hentz Profile Picture
    on at

    I have the same issue. My script is correct. I created a business rule when the first field not contain data to  set the second field with the primary field, in this case, null. but this is not useful, two customizations to do the same thing. it is a bug or the product now works this way?

  • Community Member Profile Picture
    on at

    I have the same issue for a CRM 2013 on-premise environment. I think the issue may be caused by the business requirement of the field.

    If the field is business required, removing the value will not trigger onChange event.

    Hope this will be fixed by Microsoft CRM team as soon as possible, because this is causing a lot of problems.

    Regards,

    Jaimie

  • Suggested answer
    Community Member Profile Picture
    on at

    I have not tested this, but I it would be worth a try...remove the business required on the field, then set business required on the form OnLoad event instead using javascript. You would think that the form would do the equivalent when it loads, but who knows. The only problem is that you would need to add this logic to each form on the entity if it works.

    Let me know how it goes!

  • Ferdy Griffioen Profile Picture
    25 on at

    I'm having the same problem.

    When the field is 'optional' or 'recommended' the function passed in the 'addOnChange' function will be executed when the field is cleared. But when the field is 'required' and the user clears the field the onchange is not fired.

    I think (note: not sure but 'I think') that it has something to do with the new 'field notifications' feature in CRM2013. What this does is put a nice cross in a hexagon when a required field is empty. This happens onChange and probably cancels out the onChange you/I place on the field via JS code.

    I also tested it on CRM2011 to be sure (as this does not have the field notification feature) but here all works fine.

    Going to search and maybe contact microsoft about it. Keep you posted.

  • Community Member Profile Picture
    on at

    I just encountered this problem as well - my business required field doesn't trigger an OnChange when it's cleared.  Please let us know if you get a response from Microsoft!

  • Taichi Sato Profile Picture
    180 on at

    I am having the same problem. Well, actually it doesn't matter as much in my case. But I would like to know that this behavior will be changed in future or not.

  • Suggested answer
    Stefano Miglietta Profile Picture
    5 on at

    You are right, if the field is required the event dont fire if you are removing the value....horrible.

  • Taichi Sato Profile Picture
    180 on at

    1. Open a new record

    2. Set a value "ABC" to a required field.

    3. Move the focus

    then, the onchange event is triggered!

    4. Remove the value "ABC" from the field.

    5. Move the focus.

    then, the onchange event is NOT triggered...

    But it's still okay becaue I can not save the record anyways because it is a required field.

    The real problem comes next.

    6. Set a value "ABC" to the field again.

    then, the onchange event is NOT triggered!!

    (In case, I haven't saved the record yet, I mean, the value "ABC" is definitely a changed value.)

    My custom validation code in the onchange event is not fired, which doesn't allow the value "ABC" to be saved. Yes, I could set the validation in the onsave event but I want to show the notification when the value changes.

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