Hi Tina.
Sorry for the delay. This is Juan, Toolset team leader.
Hi Tina
Sorry for the delay. This is Juan here, Toolset team leader.
I would like to bring some light to the problem that you have with events binding, related to the counters for characters left for dding a custom limit to some input fields.
document ready and cred_form_ready
cred_form_ready is executed as early as possible, after we initialize some essential form element.
document ready happens when the DOM is ready. Compared to cred_form_ready, this might happen before or after, depending on how the browser manages the code that we need to run to get to fire the cred_form_ready event. This is why we had some inconsistent results when trying to nest event callbacks, like putting a cred_form_ready callback inside a document ready callback: this should not be done.
Note that before cred_form_ready, CRED applies some bindings to the form elements, which means it adds callbacks when events happen on some form elements, like clicks, focus, blur, etc.
Note also that when running cred_form_ready, the third partly library we use to manage such events may clear the existing ones. We might review this in the future, but this was needed to manage CRED forms submitted using AJAX that need to be re-initialized again after they get successfully submitted.
This is why we have different results when document ready is fired before or after cred_form_ready in different browsers: sometimes, the custom code gets erased (or just unbinded, to be fair), which means it never gets applied.
We should use cred_form_ready as much as we can. I understand that this is a little cumbersome and unexpected, so we will review how this all gets fired in a future iteration, so we can try to restate the trust in document ready again. But right now, using cred_form_ready is the best way of making sure that your own custom events get properly mantained in all scenarios, and also re-started in case your CRED form uses AJAX.
I understand this might be a little inconvenient since most of the custom JavaScript written for forms surely relies on document ready, but again this is the only way to ensure that core and custom event callbacks do work properly with CRED forms using AJAX. Relying just in the document ready event is not enough, so we were forced to use a custom event ourselves.
Hope this helps.
Regards.