When I was looking through my demo templates, I came across an example that showed some features in qForms v2.0 that I had forgotten I implemented, but it's something that's very cool and provides a lot of flexibility. What is this code you ask? Well, it deals with the createDepedencyTo() method.
For those of you who aren't familiar with this method, in a nutshell the createDependencyTo() method is used to build rule logic into your forms. For example, maybe you only want to require a user to enter their e-mail address if they've actually selected to have something e-mailed to them. You could do that like this:
oForm.email.createDependencyTo("EmailNewsletter", "yes");In the example above, if the "EmailNewsletter" field was equal to "yes" (which might be a checkbox,) then the field "email" would be required—otherwise it would be optional.
You can actually do more than just checking simple values, but in v1, you could only affect the required status of a field.
However in v2, the code's been reworked so you can actually define how you want dependencies to work. For example, instead of making a field required, you could disable/enable the field. Or you could toggle a layer off and on. However you want the createDependencyTo() method to behave, you know have control over it by just overriding the default setDependency() method.
For some examples of what can be done, check out the example below:
Comments for this entry have been disabled.