Thanks Locke,
I’m right now on holidays and supporting 1.1 branch is next on my todo list probably at the begining of February.
Thanks Locke,
I’m right now on holidays and supporting 1.1 branch is next on my todo list probably at the begining of February.
Hi,
First, this extension is very good.
Second, a little suggestion.
Don’t tie your component to CHTML Helper because it restricts it’s use.
For example I wanted to integrate your component with the uniform extension and to do that I have to change your code, something that I don’t want to do.
So instead of:
///EHtml
public static function beginForm($action='',$method='post',$htmlOptions=array()){
return self::getJValidateInstance()->beginForm($action,$method,$htmlOptions);
}
///EJFValidate
public function beginForm($action='',$method='post',$htmlOptions=array())
{
if( $this->enable === true)
{
if( ! isset($htmlOptions['id']))
$htmlOptions['id'] = $this->getCurrentFormId() ;
$this->_formId = $htmlOptions['id'];
$this->_scenario = null;
$this->_rules = array();
$this->_messages = array();
}
return CHtml::beginForm($action,$method,$htmlOptions);
}
I suggest something like this:
///EHtml
public static function beginForm($action='',$method='post',$htmlOptions=array()){
list($action,$method,$htmlOptions) = self::getJValidateInstance()->beginForm($action,$method,$htmlOptions);
return parent::beginForm($action,$method,$htmlOptions);
}
///EJFValidate
public function beginForm($action='',$method='post',$htmlOptions=array())
{
if( $this->enable === true)
{
if( ! isset($htmlOptions['id']))
$htmlOptions['id'] = $this->getCurrentFormId() ;
$this->_formId = $htmlOptions['id'];
$this->_scenario = null;
$this->_rules = array();
$this->_messages = array();
}
return array($action,$method,$htmlOptions);
}
By doing this any helper can use the standard functions of your component and would be very easy to integrate with the uniform extension.
Hi Raoul, this extension looks nice, exactly what frameworks need nowadays
Do you have an ETA for v1.1 support?
Also, one of your examples shows using EHtml instead of CHtml, but the example uses CHtml when calling activeLabel.
Would it not be possible to use EHtml completely throughout the form, to maintain consistency? (Assuming EHtml extends CHtml?)
Thanks!
Also, does this extension have any issues w/ multiple models in the same form? I’m betting it doesn’t, but just want to make sure
hi intel352,
yes I do plan to release a new version that will be compatible with 1.1 … in fact I plan to do that this week-end. Regarding the usage of EHtml, I plan to make it inherit from CHtml (followinf lightglitch suggestion) and so it should be possible to not have to switch between both.
As for multiple model in the same form … hummm … that’s one test I didn’t do (sorry). Another thing to do this week-end
I’ll keep you inform
ciao
Hi all,
I have released today a new version of the [size="4"]JFormValidate [/size]extension, that is compatible with Yii 1.1.x.
[font="Courier New"][color="#FF0000"]version 1.1.0[/color] - Yii 1.1 support
- no need to call EHtml::setScenario as scenario is get directly from the model
- reduce dependencies between the EJFValidate component and CHtml Yii helper class. Note that CHtml::activeName(), CHtml::activeId(), CHtml::encode() and CHtml::normalizeUrl() are still directly called by the extension, but all other calls have been moved to EHtml. It is not possible anymore to directly use the underlying application component, EHtml must be used instead.[/font]
I have also updated the JFormValidate WebSite where you can see some demo of the extension (plenty of forms validating … or not), and the related documentation.
Have fun !
Checked out your demos, excellent job
Thanks
Thanks Raoul for the great job!
Is there a way to use the extension with the new form builder functionalities (http://www.yiiframework.com/doc/guide/form.builder)?
Thanks in advance
Hi Paolo,
thanks for your message.
unfortunatly right now, the jformvalidate extension can’t be used with the form builder and the CForm class. I had a quick look at the source code and it doesn’t seems to me that integration of jformvalidate would be an easy task. However, if I receive many demands, I may consider to do it … when I find time
Many thanks for this extension, Raoul.
I’m trying to show errors after a submission. From the Validation documentation, I thought a call to [font=“Courier New”]validator.showErrors()[/font] would do the trick. I don’t know if this is even the right way to do it.
I first ran into a problem trying to get a reference to the validator object - I could not find a reference to it anywhere. So I tried assigning the [font="Courier New"]$().validate()[/font] call to a global variable which I use in the submit success function. I did this by modifying the [font="Courier New"]EJFValidate.prepareOptions()[/font] method.
I then coded the submit button as follows:
echo EHtml::ajaxSubmitButton('Subscribe!',
array('default/subscribe'),
array(
'success'=>'js:function(data,status){
data = JSON.parse(data);
if (data.hasErrors) {
// This doesn't work (global variable subsValidator
// correctly references validator object, and
// data.errors correctly formatted json object):
subsValidator.showErrors(data.errors);
// This code does work - but it's ugly:
var errorStr = "";
for (var fld in data.errors)
errorStr += fld+": "+data.errors[fld]+"\n";
alert("Errors found:\n"+errorStr);
}
else {
alert("Contact Saved: "+data.id);
$("#subscribeForm").dialog("close");
}
}'),
array('id'=>'btnSubscribeSubmit')
);
(Notice the [font="Courier New"]data = JSON.parse(data);[/font] line. In all other success callbacks, json encoded data is correctly parsed as a json object, but not in EHtml::ajaxSubmitButton.)
I guess I could do a whole bunch of jquery manipulation but since the validator has already been set up it makes sense to use it’s functionality.
Please let me have any suggestions on how to achieve the post-submission error handling.
Hi Timbo,
thanks for using this extension
I’m not sure I understand what you want to achieve, and when you say “I’m trying to show errors after a submission” is it that you want to display validation error messages in alert box ? … Could you please give me more information so I try to help.
ciao
I want to display errors on the page in exactly the same way as client-side errors are displayed normally, ie: [font=“Courier New”]EHtml::errorSummary()[/font]. But I don’t want to just replace the errorSummary div as you have done in one of your examples because:
[list=1]
[*]I also want the input class updated to highlight the error
[*]I need to update the page with some of the data returned and do other processing
[/list]
So given the error list passed as data to the success method, I want to update the standard error message display.
I hope that makes it clearer.
ok, now I understand better … and I have to confess that I have no idea how to solve your problem. However I’ll try to work on this subject as it could be intresting to others.
The only thing I miss is free time … so please be patient, and let me know if you find something.
ciao
Here’s, I think, a very common situation where you’d need to be able pass another parameter to the remote validation script (unless I’m missing something…)
Consider a remote lookup of a username field - a check to make sure the username that’s entered is unique - not already in the database.
setting up a remote script that checks to see if the username exists in the database works perfectly when you are creating a user, or changing the username. But what if you’re updating the record, and not changing the username (say, changing the address, or phone fields)?
Then the form gets submitted - and the remote validation script kicks in for the field "username" and it returns an error - because, yes, that username is already taken (by this user!).
So, it seems I’d need to pass the id of the user along with the username to the remote validation script - that way if the id of the record it finds matches the submitted id, the script will know to ignore the match and move on.
So… unless I’m missing something, it would be quite useful to pass the id of the record in question to the remote validation script.
-Charlie
hi cshehadi,
yes, your point is right and I’ll see what is possible to do … unfortunatly I won’t be available in the next 2 weeks, but as soon as I have free time, I’ll work on that.
[edit]
to pass an aditional parameters just before ajax submition, you can refer to the Custom Submit Handler demo form (form17).
But doesn"t this id is the one of the currently logged-in user ? why can’t you get it from Yii::app()->user->id ?
Another solution is to insert it inside the form, as an hidden field …
ciao
Regarding Ajax validation, are you aware of CActiveForm? I just saw it in the forums. CActiveForm
no, I missed this post from qiang. It seems intresting and I’ll take a look
From what I saw, CActiveForm is not really a client side validation form widget as the validation does not take place on the client side, but on the server side by ajax calls.
I didn’t claim it did client side validation, I only talked about Ajax.