Yii Framework Forum: [EXTENSION] wvActiveForm - Yii Framework Forum

Jump to content

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

[EXTENSION] wvActiveForm CActiveForm with client validation Rate Topic: -----

#1 User is offline   Rangel Reale 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-January 10

Posted 29 May 2010 - 01:37 PM

wvActiveForm is a CActiveForm descendant that validates the input on client with jQuery, using the rules defined at the model, while also supporting custom rules.

http://www.yiiframew...n/wvactiveform/

Validators:

* Required
* Number
* String (length)
* Email
* Default value (displays value that disappear on field click)
* No whitespace
* URL
* Manual rules

Rules:

* jQuery.Validate
* jQuery.Numeric
* jQuery.DefaulValue
* jQuery.keyFilter

CValidator supported:

* CRequiredValidator
* CStringValidator
* CNumberValidator
* CEmailValidator
* CUrlValidator
0

#2 User is offline   lightglitch 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 05-January 10

Posted 29 May 2010 - 07:17 PM

Instead of reimplementing all the rules you could use jformvalidate in your extension.
0

#3 User is offline   Rangel Reale 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-January 10

Posted 29 May 2010 - 11:06 PM

View Postlightglitch, on 29 May 2010 - 07:17 PM, said:

Instead of reimplementing all the rules you could use jformvalidate in your extension.


Yes I saw it, but to use it one must modify his source code, I wanted a solution that needed no code changes, and uses CActiveForm.
0

#4 User is offline   Raoul 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 645
  • Joined: 29-November 08
  • Location:Paris, France

Posted 30 May 2010 - 07:16 AM

Hi Rangel,
it seems like a promising extension ! however, I tested it following your instructions, and I get the error :

Fatal error: Call to undefined function lcfirst() in H:\home\Project\yii.1.2\protected\extensions\wvactiveform\wvFormRules.php  on line 48


ciao
B)

ps: you're right about jformvalidate not supporting CActiveForm Widget, and I've been thinking about releasing a new version that would support CActiveForm Widget...
0

#5 User is offline   Rangel Reale 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-January 10

Posted 30 May 2010 - 01:08 PM

View PostRaoul, on 30 May 2010 - 07:16 AM, said:

Hi Rangel,
it seems like a promising extension ! however, I tested it following your instructions, and I get the error :

Fatal error: Call to undefined function lcfirst() in H:\home\Project\yii.1.2\protected\extensions\wvactiveform\wvFormRules.php  on line 48


ciao
B)

ps: you're right about jformvalidate not supporting CActiveForm Widget, and I've been thinking about releasing a new version that would support CActiveForm Widget...


Hmm you're right, lcfirst function only exists in PHP 5.3+, I've released a new version without this call.

About jformvalidate, as I started working with Yii 1.1, all my code was already using CActiveForm, so I want a method of upgrading all my applications with a minimum effort, that's why I created this extension.

Also, I wanted to make it easy for 3rd party developers create his own rules as extensions, again always thinking of minimum code changes.
0

#6 User is offline   freezy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 12-August 09
  • Location:Russia, Arzamas

Posted 05 August 2010 - 07:46 AM

Hello there! :)

I have some problem with latest wvActiveForm from svn, which reproduced by definition rule with option: 'allowEmpty' => false.
For example:
'telephonePresent' => array(
  'telephone',
  'length',
  'min' => 2,
  'max' => 100,
  'allowEmpty' => false,
),


I think option 'allowEmpty' is semantically equals to 'require' rule (do you think? :) ), and expected to see on page something like:
'Order[telephone]': {
            'required': true,
            'minlength': 2,
            'maxlength': 100
        },

But there is:
'Order[telephone]': {
            'minlength': 2,
            'maxlength': 100
        },


Thanks!

Possible solution within attachment (maybe we need move $allowEmpty and related processing to base class).

Attached File(s)


0

#7 User is offline   Rangel Reale 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-January 10

Posted 05 August 2010 - 09:05 AM

View Postfreezy, on 05 August 2010 - 07:46 AM, said:

Hello there! :)

I have some problem with latest wvActiveForm from svn, which reproduced by definition rule with option: 'allowEmpty' => false.
For example:
'telephonePresent' => array(
  'telephone',
  'length',
  'min' => 2,
  'max' => 100,
  'allowEmpty' => false,
),


I think option 'allowEmpty' is semantically equals to 'require' rule (do you think? :) ), and expected to see on page something like:
'Order[telephone]': {
            'required': true,
            'minlength': 2,
            'maxlength': 100
        },

But there is:
'Order[telephone]': {
            'minlength': 2,
            'maxlength': 100
        },


Thanks!

Possible solution within attachment (maybe we need move $allowEmpty and related processing to base class).


Hmm I think the main problem is, Yii doesn't take allowEmpty in account when checking for required fields (CModel::isAttributeRequired), and also doesn't add the '*' on the field's label:

	public function isAttributeRequired($attribute)
	{
		$model=$this->resolveAttribute($attribute);
		foreach($model->getValidators($attribute) as $validator)
		{
			if($validator instanceof CRequiredValidator)
				return true;
		}
		return false;
	}


This "allowEmpty" conflicts with the required validator, but on the case of a form, the field IS required when allowEmpty is false, so I think your patch is correct.

I added it to the SVN.
0

#8 User is offline   freezy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 12-August 09
  • Location:Russia, Arzamas

Posted 13 August 2010 - 08:20 AM

Hello again! :)

I've explored a new bug (or feature :) ). For example, we defined such rule
array(
  'test',
  'length',
  'min' => 4,
  'max' => 20,
  'allowEmpty' => false,
  'message' => Yii::t('error', 'Please enter valid {attribute}.'),
  'tooShort' => Yii::t('error', 'Please enter valid {attribute}.'),
  'tooLong' => Yii::t('error', '{attribute} is too long.'),
  'on' => 'update',
),


The problem is shown, when another language set in config. We see default english-labeled attribute.

To solve the problem, please fix wvActiveForm.php:
public function addValidationForValidator($model, $id, $name, $attributeName, CValidator $validator)
{
  $attributeName = $model->getAttributeLabel($attributeName); // added

0

#9 User is offline   Rangel Reale 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-January 10

Posted 14 August 2010 - 10:40 AM

View Postfreezy, on 13 August 2010 - 08:20 AM, said:

Hello again! :)

I've explored a new bug (or feature :) ). For example, we defined such rule
array(
  'test',
  'length',
  'min' => 4,
  'max' => 20,
  'allowEmpty' => false,
  'message' => Yii::t('error', 'Please enter valid {attribute}.'),
  'tooShort' => Yii::t('error', 'Please enter valid {attribute}.'),
  'tooLong' => Yii::t('error', '{attribute} is too long.'),
  'on' => 'update',
),


The problem is shown, when another language set in config. We see default english-labeled attribute.

To solve the problem, please fix wvActiveForm.php:
public function addValidationForValidator($model, $id, $name, $attributeName, CValidator $validator)
{
  $attributeName = $model->getAttributeLabel($attributeName); // added



Hmm are you sure about this? Are you calling this method directly? Because it is only called in the "checkValidation" method, and it already does this.

	protected function checkValidation($model,$attribute,&$htmlOptions=array(),
		$fieldOptions=array())
	{
...
		CHtml::resolveNameID($model,$attribute,$htmlOptions);
		$attributeName = $model->getAttributeLabel($attribute);
...
		foreach ($model->getValidators($attribute) as $validator)
			$this->addValidationForValidator($htmlOptions['id'], $htmlOptions['name'], $attributeName, $validator);
...
	}

0

#10 User is offline   freezy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 23
  • Joined: 12-August 09
  • Location:Russia, Arzamas

Posted 15 August 2010 - 12:58 AM

Yeah, it seems i was wrong :) Thanks :)
0

#11 User is offline   dimilow 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 85
  • Joined: 16-March 09

Posted 27 October 2010 - 04:53 AM

Does it works with form builder? I tested it with form builder but it doesn't works out of the box, doesn't know where to modify though, any ideas?
tipstank.com - where I share my coding stuff
0

#12 User is offline   Rangel Reale 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 14-January 10

Posted 27 October 2010 - 08:02 AM

View Postsumwai, on 27 October 2010 - 04:53 AM, said:

Does it works with form builder? I tested it with form builder but it doesn't works out of the box, doesn't know where to modify though, any ideas?


What form builder? If it uses CActiveForm it should work, if it uses CForm, then it won't.
0

#13 User is offline   rmrcoxa 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 27-February 09

Posted 01 November 2010 - 01:39 PM

When I try to use qtip layout, I got a javascript error.

'layout'=>'qtip'


Error: $(this).data("qtip") is undefined
Source-code: jquery.qtip-1.0.0-rc3-dm.js
Line: 38
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