[EXTENSION] wvActiveForm CActiveForm with client validation
#1
Posted 29 May 2010 - 01:37 PM
http://www.yiiframew...n/wvactiveform/
Validators:
* Required
* Number
* String (length)
* 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
#2
Posted 29 May 2010 - 07:17 PM
#3
Posted 29 May 2010 - 11:06 PM
lightglitch, on 29 May 2010 - 07:17 PM, said:
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.
#4
Posted 30 May 2010 - 07:16 AM
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
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...
#5
Posted 30 May 2010 - 01:08 PM
Raoul, on 30 May 2010 - 07:16 AM, said:
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
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.
#6
Posted 05 August 2010 - 07:46 AM
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?
'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)
-
wvFormStringValidator.php.zip (1.03K)
Number of downloads: 2
#7
Posted 05 August 2010 - 09:05 AM
freezy, on 05 August 2010 - 07:46 AM, said:
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?
'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.
#8
Posted 13 August 2010 - 08:20 AM
I've explored a new bug (or feature
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
#9
Posted 14 August 2010 - 10:40 AM
freezy, on 13 August 2010 - 08:20 AM, said:
I've explored a new bug (or feature
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);
...
}
#11
Posted 27 October 2010 - 04:53 AM
#13
Posted 01 November 2010 - 01:39 PM
'layout'=>'qtip'
Error: $(this).data("qtip") is undefined
Source-code: jquery.qtip-1.0.0-rc3-dm.js
Line: 38

Help













