Skip to main content
Post a question

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id : wmFddFBTx0WFIHmq4tnaQ1
Microsoft Dynamics CRM (Archived)

Javascript, onChange events no longer work on an empty field

Like (0) ShareShare
ReportReport
Posted on 9 Oct 2013 07:34:06 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

  • Suggested answer
    ALTOSHAAM Profile Picture
    ALTOSHAAM 180 on 01 Dec 2014 at 07:14:46
    RE: Javascript, onChange events no longer work on an empty field

    Hi Hussman,

    This issue was solved in Service Pack 1 (support.microsoft.com/.../2941390)

    "JavaScript methods will not trigger when a business required field is changed to be blank."

    Hope this helps.

  • Taichi Sato Profile Picture
    Taichi Sato 180 on 07 May 2014 at 06:58:37
    RE: Javascript, onChange events no longer work on an empty field
    I found another similar issue.
    This happens at a lookup field whose field requirement is "Optional".

    step1. Set a value "ABC" to the field manually.
    step2. Remove the value "ABC" from the field by JavaScript like "Xrm.Page.getAttribute('new_account').setValue(null);"
    step3. Set the value "ABC" to the field manually again.

    Then,

    Problem1 : the OnChange event is not fired at the step3 when you set "ABC".
    Problem2 : After step3, null is returned by JavaScript "Xrm.Page.getAttribute('new_account').getValue()".
  • Ferdy Griffioen Profile Picture
    Ferdy Griffioen 25 on 30 Apr 2014 at 07:52:33
    RE: Javascript, onChange events no longer work on an empty field

    @Tachi Sato:

    I'm also working (at the moment) with the entire attribute setNotification etc and stumbled against the same problem (like 5 minutes ago).

    I don't have a work around for it, but for our situation it is not that big of a deal.

    But just like you I hope Microsoft doesn't closes this as a 'by-design'

  • Taichi Sato Profile Picture
    Taichi Sato 180 on 30 Apr 2014 at 07:45:27
    RE: Javascript, onChange events no longer work on an empty field

    @Ferdy Griffioen:

    Assuming that "ABC" is an invalid value, when I set "ABC" to the required field, the notification "Don't input ABC!!" is displayed by the code I wrote in the onchange event.

    And I remove the value "ABC". Then, the notification is removed. (don't know why. I can't handle it anyways) And the notification is never displayed when I set "ABC" to the required field again. In this case, "ABC" could be saved.

    I hope this will not be closed with 'by-design'....

    Thanks for your reply.

  • Ferdy Griffioen Profile Picture
    Ferdy Griffioen 25 on 30 Apr 2014 at 07:26:14
    RE: Javascript, onChange events no longer work on an empty field

    @Taichi Sato:

    I think so yeah. But the problem is that it doesn't and I think Microsoft did this 'by-design'. Because why trigger a onchange (which cost a (tiny) bit of performance) while the user can't save the entity.

  • Taichi Sato Profile Picture
    Taichi Sato 180 on 30 Apr 2014 at 07:22:52
    RE: Javascript, onChange events no longer work on an empty field

    @Ferdy Griffioen

    So, we arrived at the conclusion that the onchange should be triggered when I remove the value "ABC" at step4. If it is triggered, the onchange of step6 would be triggered too.

  • Ferdy Griffioen Profile Picture
    Ferdy Griffioen 25 on 30 Apr 2014 at 07:06:38
    RE: Javascript, onChange events no longer work on an empty field

    @Taichi Sato:

    Step6 makes sense in a weird way.

    Because you set the value 'ABC' in the field (@ step 2) the value on that particular moment is 'ABC'. On step 4 you remove the value and the onchange is not triggerd. But at this particular moment the value (in the backend) is still 'ABC' because (for some stupid reason) the backend value is not cleared. I think this is done because the entity will not save due to a required field being empty, and thus it doesn't matter what the backend value is of that field.

  • Taichi Sato Profile Picture
    Taichi Sato 180 on 30 Apr 2014 at 06:51:14
    RE: Javascript, onChange events no longer work on an empty field

    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.

  • Suggested answer
    Stefano Miglietta Profile Picture
    Stefano Miglietta 5 on 17 Apr 2014 at 11:20:12
    RE: Javascript, onChange events no longer work on an empty field

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

  • Taichi Sato Profile Picture
    Taichi Sato 180 on 26 Feb 2014 at 22:27:48
    RE: Javascript, onChange events no longer work on an empty field

    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.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,626 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,558 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans
Loading started