Yii Framework Forum: Yii Bootstrap Form Validation With Highlight - Yii Framework Forum

Jump to content

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

Yii Bootstrap Form Validation With Highlight Yii Boostrap form validate and highlight on ajax-submit Rate Topic: -----

#1 User is offline   Edgar Kuskov 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 22
  • Joined: 07-December 12
  • Location:Konstanz, Germany

Posted 08 February 2013 - 04:58 AM

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!
"Don't start what you can't finish"
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