I love the CHtml::ajaxButton() functionality. Unfortunately, I can’t get it to work in a complex form situation that I have.
The form is a member profile, comprising several different kinds of records/models. Each portion of the form is loaded using a jQuery $("#myform").load("my/url") type of call. For example, one section loads multiple address records using the MemberAddress model, while basic information is loaded using the Member model. Some of the loaded forms even render using other load() calls.
The result is that the Yii form code for the ajaxButton doesn’t seem to get added in that situation. The code I see in Firebug for simple forms at the bottom of the page that sets up a jQuery click() function for the button does not appear in the complex form.
Any ideas on how to get it to work in this situation? Do I need to include some .js files in my loaded subforms?
I’m not a JQuery expert but I think that if you ajax load a form that contains the CHtml::ajaxButton(), the button will not register its onSubmit handler function as the Document.onload event was already fired (when the container page loaded). JQuery provides the live() function to bind event and handler … in live (that is, anytime). Maybe that can help you solving your problem …
Yes, That’s why i asked the question if you add the submit button in the form loaded with ajax. You will need to either use live to bind the events or add the ajaxButton in the form without loading it via ajax.