I've been asked to enquire whether the following concept is possible,
we have some realtime Javascript validation on a web-form, but instead
of having the error messages stored in two locations (in the js script
and in the validation's action.xml file), is it possible to centralise
these messages just into the Agavi's module/<modulename>/validate/
action.xml file.
Then in the input view class, have the XHTML function call (i thinking
out loud) request the validation xml file, the file name could be
passed by the action to the view with an attribute setting or so.
Can I use the validation Manager in the action/view to gain all the
possible error messages, then parse them to JSON and print it to a JS
variable or so.
...or should I use Agavi Configuration interface to load in the
validation xml file and return a structure PHP data type/object which
can then be parsed into JSON.
Cheers folks,
Jeramy Wenserit (E_mE)
e: evercl...@gmail.com
_______________________________________________
users mailing list
us...@lists.agavi.org
http://lists.agavi.org/mailman/listinfo/users
this ("how can I do client-side validation, like, as people type,
using server-side validators") is a question that has been brought up
before many times, with no useful answer yet.
However, I think I just had a nice idea on how to do that.
Basically, what you want to do is submit the contents of the form via
XMLHTTPRequest in the background, and get back any validation errors
from the server. However, if all is good, then it would run the
Action, which in 99% of the cases is *not* what you want.
Hence you need to be able to run validation without running the action.
Which, as it turns out, is wonderfully simple to do.
<validator class="equals" source="headers" required="false">
<argument>X-Requested-With</argument>
<ae:parameter name="value">lolcats</ae:parameter>
</validator>
This validator will only run if the X-Requested-With HTTP header is
sent in the request, and in that case, it will always fail, because
all the JS frameworks send "XMLHTTPRequest" as the value there.
Then, you can
a) use executeJson() in your error view to collect validation info
from the validation manager and return that to the browser, where you
insert it using javascript, or
b) load a simple layout with just html and body elements in the
decorator (don't forget the base href!) and switch on FPF there
(ajaxHtml might be a better output type here), then re-insert the body
contents into the document (but that's tricky, with field focus etc,
especially as people are typing).
In any case, it's a good way of running the validation while making
sure the action is not executed.
Cheers,
- David
P.S: if you just want to submit forms using ajax or so, then you don't
really need anything like that, because that "just works"... I was
assuming that you want to periodically check if the entered values are
valid while the user is filling the form, or while he is typing, or
whenever he changes to a new form field or so.
So if anyone is interested in working (or you have already something
you're willing to share) on a FPF-JSedition, drop me a mail.
Cheers,
Jordi