In this webinar, our experts showcase a variety of demo use cases of how different components of the...
I recently encountered some difficulty firing a JavaScript event off when a bit field was marked as True. The following code worked fine when the bit field was a radio button on the form, but the event would not fire until I tabbed out of the field when I had the bit field formatted as a checkbox. This was in my onChange() event for the bit field.
hideField = function() {
if (crmForm.all.some_bit_field.DataValue == 1)
//Hide Some Fields
}
It came to my attention that checkbox-type bit fields are handled a bit differently in Dynamics CRM. The onChange () event for a checkbox will not be fired until we leave the field. This was a problem as the customer expected the field to show/hide immediately when the field was changed, not when we tabbed off the field.
To solve the problem we simply added some Event Handling code into the onLoad event area of our entity form. With this piece of code included, the field will show/hide as soon as the value changes, not when we tab off the field.
crmForm.all.your_checkboxfield.onclick = function() {
crmForm.all.your_checkboxfield.FireOnChange();
}
Using the code above, the onChange () event will fire TWICE: Once when the field is changed and once when we tab off the field. If this is a concern in your implementation you can use the following code in the onLoad() event to ensure the event only fires once (Remember to remove the code from the fields' onChange event is you use the code this way!)
crmForm.all.your_checkboxfield.onclick = function() {
//Existing onChange() code
}
Happy Coding!
Thanks for posting this. This is exactly what I needed.
Thank you soo much for this post
it was of great help...