Yii Bootstrap Form Validation With Highlight

Hello ever1,

i would like to share a small part of code for those, who have problems with a good form validation and highlight of the success or error fields with bootstrap yii. Here it goes:




	$form = $this -> beginWidget('bootstrap.widgets.TbActiveForm', array(

			'id' => 'user-time-form',

			'type' => 'horizontal',

	));



and now submit button:




$this -> widget('bootstrap.widgets.TbButton', array(

				'buttonType' => 'ajaxSubmit',

				'icon' => 'ok',

				'url' => Yii::app() -> createUrl('hr/userTime/create'),

				'label' => 'Submit',

				'ajaxOptions' => array('success' => 'function(data){

						var obj = $.parseJSON(data);

						if(obj.status=="success"){

							$("#newUserTime").modal("hide");

							setTimeout(function(){location.reload(true);},400);

						} else {

							$("#userTime-form-error-div").show();

							$("#userTime-form-error-div").html("");

							var $inputs = $("#user-time-form :input");

						    $inputs.each(function() {

						        $(this).removeClass("error");

								$(this).closest(\'div[class^="control-group"]\').addClass("success validating");

						    });

							for (var p in obj) {

								if(document.getElementById(p)) {

									$("#"+p).closest(\'div[class^="control-group"]\').removeClass("success");

									$("#"+p).closest(\'div[class^="control-group"]\').addClass("error");

								}

								$("#userTime-form-error-div").append(obj[p]  + "<br/>");

							}

						}

					}'),

		));



I wish every1 a nice day and weekend!