Commits

christiansalazar  committed 896208b

ENH#1 - create a onChange event handler.

  • Participants
  • Parent commits e5a23c4

Comments (0)

Files changed (3)

File DippyWidget.php

 	public $validateErrorText = 'Please type a valid value';
 	public $validateRegExp = '';
 
+	public	$onChange; // function(dippyId, selectdId){   } 
+
 	public $onSuccess;
 	public $onError;
 	private $_baseUrl;
 		parent::init();
 		if($this->id == null)
 			$this->id = 'dippy0';
+		if($this->onChange == null)
+			$this->onChange = "function(){}";
 		if($this->onSuccess == null)
 			$this->onSuccess = "function(){}";
 		if($this->onError == null)
 			'logid'=>$this->logid,
 			'onSuccess'=>new CJavaScriptExpression($this->onSuccess),
 			'onError'=>new CJavaScriptExpression($this->onError),
+			'onChange'=>new CJavaScriptExpression($this->onChange),
 			'parent'=>$this->parent,
 			'deleteconfirmation'=>$this->deleteConfirmation,
 			'enterSaveText'=>$this->enterSaveText,
 				'attribute'=>$this->attribute,
 			)),
 		));
-		Yii::app()->getClientScript()->registerScript($this->id
-				,"new Dippy({$options})");
+		Yii::app()->getClientScript()->registerScript($this->id,
+				"new Dippy({$options})");
 
 	}// end run()
 	
 </div>
 ~~~
 
+#onChange Event
+
+Call a JS function whenever a Dippy selection changes. You can use the
+same JS function for all dippy widgets, so look for the dippyId argument to
+identify wich widget is making the call. The selectionId arguments is the
+primary key passed when dippy makes a refresh.
+
+
+~~~
+<?php
+$this->widget('ext.dippy.DippyWidget',array(
+	'title'=>'Selection Values:',
+	'id'=>'dippy2',
+	'controllerName'=>'site',
+	'parent'=>'dippy1',
+	'modelName'=>'OptVal',
+	'parentKey'=>'artoptid',
+	'attribute'=>'name',
+	'onChange' => "function(dippyId, selectionId){ ...yourcodehere..  }",
+));
+?>
+~~~
+
+Example:
+
+in the same view were dippy widget is located, insert a text field:
+
+	echo CHtml::textField('dippy2cur');
+
+now add the onChange event handler, like this:
+
+	'onChange' => "function(wid, id){ $('#dippy2cur').val(id);  }",
+
+makes a selection on your Dippy widget and you will observe the text field
+changes too.  This would be usefull when validation is required on your form.
+
 #Your models:
 
 
 ('40000000', '00000002', 'BAG');
 ~~~
 
-
-

File assets/dippy.js

 				var _div = item.parent();
 				var _this = _div.data('_this');
 				_this.change(item, prior);
+				options.onChange(options.id, id);
 			}
 		});
 	}