|
![Picture of Sebastian Wais Picture of Sebastian Wais](/picture/user/236170.gif) Sebastian Wais - 2006-12-20 16:57:00
Hi Manuel.
I'm using this class, but I'm having a problem.
I have a form to create or renew a membership. I want to use the same form (because it have many common fields), and I want to ask the personal details if the cliente is going to create a new account (some of this fields are required), but if he is going to renew I don't want to validate those fields again (probably removing them using JS).
Is there an "easy way" for these? I think I will use a private "ValidateOptionalValue" and when it is a renew just hiding the fields and fill them with this information... but I don't like this idea... Any suggestion?
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2006-12-20 19:30:52 - In reply to message 1 from Sebastian Wais
I am not sure if I understand the situation.
I think you can use the SubForm property to just validate the right set of fields depending on the submit button that is used.
If a submit button has a SubForm identifier associated, when the form is submitted with that submit button, only the form fields with the same SubForm identifier are validated.
If a submit button does not have a SubForm identifier associated, when the form is submitted with that submit button, all the form fields are validated.
![Picture of Matías montes Picture of Matías montes](/picture/user/234588.jpg) Matías montes - 2006-12-21 13:22:16 - In reply to message 2 from Manuel Lemos
What my friend Sebastián is trying to accomplish is somthing different.
He has a form that will or won't validate its fields depending the checked value of a radio button.
I personally couldn't solve his problem. Perhaps you could give him some insight on this.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2006-12-21 16:09:56 - In reply to message 3 from Matías montes
In that case, currently, there is no built-in way to achieve that directly.
What I think I can do is to implement a new action to switch value of a SubForm associated to a submit input, so you could connect the checkbox input to the submit button via the ONCHANGE event.
This way the form would validate only the fields in a SubForm or all fields depending on the state of the checkbox. Is this what you want?
![Picture of Sebastian Wais Picture of Sebastian Wais](/picture/user/236170.gif) Sebastian Wais - 2006-12-21 17:26:19 - In reply to message 4 from Manuel Lemos
Exactly what we were thinking. Thank you, Manuel y gracias Matías.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2007-02-27 06:03:34 - In reply to message 5 from Sebastian Wais
I have not yet made possible what I described above, but I just added an example plug-in class that implements a new custom validation type.
You can learn how to implement custom validation type from that example. Then you can adapt the example to validate the right fields depending the conditions that you have evaluated. Just let me know if you have other difficulties.
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2007-06-03 05:29:31 - In reply to message 5 from Sebastian Wais
By popular demand, I finally implemented a way to determine that an input will only be validated if another input (checkbox, radio or custom) is checked.
Now you can use the DependentValidation input parameter to specify the identifier of the other input that determines whether validation will be performed.
I just uploaded the new version. Take a look at test_dependent_validation.php example script to see how it works in practice.
Thank you for the suggestion.
![Picture of Form Class Picture of Form Class](/graphics/unknown.gif) Form Class - 2007-06-06 03:27:29 - In reply to message 7 from Manuel Lemos
Manuel,
This is an interesting feature and I was breaking my head earlier on trying to accomplish it using the older forms class. However, the feature you implemented assumes the dependent input be radio/checkbox and it be checked. We have a bit more complicated validation and this new feature still will not meet our requirement. We have a case where some countries do not have Zip codes at all and we need to ValidateAsNotEmpty the Zip code field for countries that have Zip codes. So in this case, the DependentInput would be a country-select (not radio/checkbox) and the value is any country that has Zip codes (not checked).
Would you be able to enhance this feature to include other input types with a DependentInputValues attribute that accepts an array of values that need the input (Zip code field in our case) to go through validation? When implemented, this feature can be used in the radio/checkbox scenario, too without many changes to existing applications because if DependentInputValues is not set, it could be assumed as checked/not-empty. Since this is a fairly new feature, I guess it is safe to enhance it at this stage.
TIA
![Picture of Manuel Lemos Picture of Manuel Lemos](/picture/user/1.jpg) Manuel Lemos - 2007-06-06 04:19:43 - In reply to message 8 from Form Class
It is not quite viable for me to implement all sorts validation types that applications may need. It would take me a lot of time and it make the main class further bloated.
However, I have anticipated the need of some developers to perform types of dependent validation that is very specific to their applications.
The dependent validation also supports custom inputs besides checkbox and radio. Therefore you can write a small plug-in class that you can use to perform the kind of dependent validation you need.
You just need to implement the GetCheckedState and GetJavascriptCheckedState functions.
The GetCheckedState function should return 1 if the validation is to be performed. The GetJavascriptCheckedState should return a Javascript expression that evaluates true when the validation is to be performed on the browser side before the form is being submitted.
Just try implementing your custom validation plug-in class and let me know if you have difficulties to write such functions.
![Picture of Erik de Bos Picture of Erik de Bos](/graphics/unknown.gif) Erik de Bos - 2012-01-18 08:21:31 - In reply to message 9 from Manuel Lemos
Hi there Manuel,
Dealing with the more complex parts of your beautiful library I find myself at the point where I need a validation that is dependent on the value of a select field, and I want to implement it like you describe here.
However, before I start I had one question: Does the dependent validation take care of the client side validation too?
I can't really see how modifying the GetCheckedState and GetJavascriptCheckedState will affect the javascript...
|