Yii Framework Forum: CHtml::ajaxButton not working - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CHtml::ajaxButton not working Rate Topic: -----

#1 User is offline   tb67 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 07-March 11

Posted 01 June 2011 - 02:37 PM

Hi...

Getting very frustrated here trying to use an ajaxButton...one of the things that is annoying me is that I have the 'same' code working just the same on another project. It may be that I am blinded to something obvious as often happens when looking at something for too long.

The idea is that I have a CActiveForm which has a ajaxButton as its submit button. The is set via css to display: none. The reason for this is that I am displaying the form in a jQuery UI dialog box and am using the dialog button to submit the form, it looks nicer this way. So when the dialog button is pressed it triggers the click event of the ajaxButton which should submit the form. Code below. It is not working - in firebug there is no ajax call being made from the browser.

Controller Code:
public function actionAjaxSubmitRegistrationForm() {
  echo "hello"; // just to test ajax return
}


Form Code (only relevant part):
	<?php echo $formUserRegistration->labelEx($modelUserRegistration,'pw'); ?>
	<?php echo $formUserRegistration->textField($modelUserRegistration,'pw'); ?>
	<?php echo $formUserRegistration->error($modelUserRegistration,'pw'); ?>
</div>
<div>
	<?php
	echo CHtml::ajaxButton(
		'Sign Up',
		'ajaxsubmitregistrationform',
		array(
			'type'=>'POST',
			'success'=>'function(data) {
				alert('it works');
			}'
		),
		array(
			'id'=>'ajaxSubmitRegistrationForm',
			'style'=>'display: none;'
		)
	);
?>
</div>
<?php
$this->endWidget();


Dialog Javascript (only relevant part:
function showDialogRegister(data) {
	var btns = {};
	btns[data.okBtnTitle] = function() {
		//alert("clicked");
		$("#ajaxSubmitRegistrationForm").trigger("click");
		$(this).dialog("destroy");
	};
	btns["cancel"] = function(){ $(this).dialog("destroy"); };


I think that is all the code involved. Also, if anyone can suggest a better way of doing this please do, the hidden ajaxButton seems a little clumsy to me but I am pretty new to Yii and can't think of a better way to do this at the moment - and as I said, it does work on another project.

Thanks a lot for any help

tb
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 02 June 2011 - 01:22 AM

Read this guide.

The trick of trigger the ajax on the onsubmit of the form solves ALL your problem, you don't have even to put the submit/ajax button, does all JuiDialog.
0

#3 User is offline   tb67 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 19
  • Joined: 07-March 11

Posted 02 June 2011 - 04:13 PM

View Postzaccaria, on 02 June 2011 - 01:22 AM, said:

Read this guide.

The trick of trigger the ajax on the onsubmit of the form solves ALL your problem, you don't have even to put the submit/ajax button, does all JuiDialog.


thanks zaccaria - i have now have something working
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users