I once asked if the extension could be modified in order to limit the error messages shown at any one time. Here is a quick and dirty solution I just found.
could you please point me to some documentation regarding the options, in particluar for placing the error message?
(I want to use inline error messages (“span”), however I do not like the error position with radiobuttons and checkboxes. With radiobuttons, the error message is placed between the first radiobutton and its label. I’d like to have it placed before the entire list of options.)
the only documentation I can think of is the one of the JQuery Validate plugin itself. It can be found here. Check the ‘Demo’ part, it contains some positioning for error messages.
I’ve ran into problems with hidden fields that I add myself - their names were shortened onSubmit (normalized names were restored). Here’s patch to leave off non-normalized hidden fields:
I was able to port the validation code I had from another non-Yii app and get things going quick.
However,
I am trying to figure out how to create a cancel button that will submit the form but skip/bypass the validation. I would like to use the controller to handle which button is clicked.
I found that the jquery.validate plugin will filter buttons that have the class "cancel" and change validator.cancelSubmit to true, but adding the class to my cancel button seems to only stop the submit and validation keeping my in the form.
I may be off base with how I am trying to accomplish canceling out of a form.
I’ve been doing some tests on your scenario and I think I’ve done what you want. I’m not a JQuery expert, and in fact, you did half of the job when you deciced to use this ‘cancel’ class. As you said, it does cancel JS validation but doesn’t submit the form, so what I did is simply add a submitHandler function to the Validate Plugin options, and manually submit the form.
See the [size=“4”]Demo form[/size] and tell me if that is what you wanted to achieve. By the way, I’m curious to know in what kind of situation it could be intresting (required ?) to provide the user with 2 submit buttons, where one would skip validation ?
I was able to bypass the validation and submit the empty form.
I did run into one thing…
It looks like jQuery doesn’t include the clicked button name when submitting the form. The model array of fields is passed, just not the clicked button. This is the same whether the validation runs or not…
I have some testing to do. May have to use the submitHandler to capture what button is clicked and set some hidden field before submission.
Yes, you’re right about the button value that is not submitte, I’ve noticed that too … I guess that with some JS test, this can be corrected.
By the way, could you please explain me why you needed to provide a submit button that would skip validation ? I’m curious to understand possible scenario regarding form submition, and I must confess that I had never thought that a not-validating submit button could be used (in particular, together with a validating one )
I am trying to contain all actions within the controller. I have a 2 step registration. Step 1, agree/disagree with our disclaimer, and step 2 is the registration form.
For the disclaimer page I have 2 buttons, agreeDisclaimer and disagreeDisclaimer. If agreeDisclaimer is clicked the form is displayed, and disagreeDisclaimer will redirect the user to the home page.
If the user decides to cancel during the registration form, I would like to skip validation and redirect the user to the home page.
The controller for requestAccount is an if statement:
if (isset($_POST['agreeDisclaimer'])) {
//render registration form
} else if ((isset($_POST['disagreeDisclaimer']) || (isset($_POST['cancelReqAccount'])) {
//redirect user to home page
} else if (isset($_POST['submitReqAccount'])) {
//process registration form
} else {
//render disclaimer
}
I know I can use javascript on the buttons to take the user back to the home page, but I like keeping all traffic through the controller. Not to mention I couldn’t figure out how to add an onClick script to the CHtml::button.
In order to know which button is clicked by the user (with or without Js Validation), you could for instance add an hidden field to your form. Then, on the ‘onClick’ event, set the value for this hidden field.
If the user clicks on the non-Js-validation submit button, the onclick handler sets the hidden field value to ‘skipJsValidation’, so on the server side, you can use the hidden field value.
On Submit, the POST array would contain :
buttonClickedByUser = 'skipJsValidation' or 'JsValidation'
This is great extension for Yii, I’m using this in all my project. But I have the little confuse.
In Yii 1.1.1, when call EHtml::setScenario(‘scenario’) in views, Yii error with message “scenario already set”, in old version Yii, it works fine. I find I can set scenario by $model->scenario = ‘scenario’, so EHtml::setScenario() can use in what case?
When I need to create a form with two models has individual rules, JFVFormValidate send error message "scenario already set", can plz help me
since 1.1 you should always set the scenario at the model level, using (like you did) $model->scenario = ‘myScenario’.
You’re right, the method EHtml::setScenario() is useless and it has no other purpose than to preserve backward compatibility with older version of the extension.
Remember that you can’t change scenario between a beginForm() and a endForm() … and that’s what may cause your second error. I don’t know how you’ve contructed your form with mixed models, but the [color="#0000FF"]JFormValidate[/color] extension is not supposed to work if you mix models inside the same form : you’ll have to create 2 forms.
Now tell me, did you notice it used to work with older extension version ? or is it the first time you mix models ?
If you post the code of your view, maybe I could help better …
ciao
ps: please note that I’ll be away since next Monday …so be patient for next reply
[size="4"][color="#0000FF"]about CActiveForm and jformvalidate extension[/color][/size]
Rangel Reale has released a new extension that adds client-side validation features to the CActiveForm Widget instead of using jformvalidate, because as he said, jformvalidate is not compatible with CActiveForm. That’s true !
So I did some tests :
copy CActiveForm from the framework to the myWebApp/extensions/jformvalidate folder
With some adjustments to set jformvalidate options, everything seemed to work fine ‘out of the box’ on simple forms (I’ve used the Contact form).
Ok, so next step would be to make some more tests and to release a new version of the jformvalidate extension. So why am I not doing it right now instead of posting endless messages on the forum ? hum … good question !
The thing is, I don’t really see why ! I mean, which scenario could justify to mix pure client-side validation, ajax validation and pure server-side validation ? Moreover, jformvalidate does support ajax validation rules (as shown in this example) so if some attributes need to be validated on the server side, that’s easy to achieve be defining an apropriate rule on the model.
If you need 3 form validation methods (client-side, ajax, pure server-side) you have 2 options :
go with jformvalidate and a ‘remote’ validation rule
use extension wvActiveForm
Consequently, and unless I really see strong positive points in doing so, I will not provide the EJFActiveForm class in a next release of jformvalidate.
I’ve been trying to get the following dropdownlist to work with a form that uses the validation extension but it seems that the extension prevents the dropdownlist from working.
When this is used by itself in a view it works as expected, the ajax code submits the selection to the controller. But if I add a form validated with the extension it stops working, that is changing the selected value of the dropdownlist does not cause the ajax code to be submit the change to the controller. In fact, just adding the following causes the problem.