Rather than block the JS entirely, I decided I'd follow what the userforms module does.
First off, you can add to Page_Controller the following, which will disable not only prototype, but also its own Validator.js and the Behaviour script Form's Validator.php class adds. This means your forms have absolutely no JS validation, and no messy code is inserted at the bottom of the page that you don't want.
class Page_Controller extends ContentController {
function init() {
// block prototype validation
Validator::set_javascript_validation_handler('none');
// load the jquery
//Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery-packed.js');
//Requirements::javascript(THIRDPARTY_DIR . '/jquery/plugins/validate/jquery.validate.min.js');
parent::init();
}
I had to place this in Page_Controller, since I was borrowing the SearchField, and I saw no need to apply validation to a search field. The trade off, of course, is now I'm responsible for the validation methods, but I'd prefer that anyway.
Now, inspecting UserDefinedForm.php, it appears that despite all the EditableFormField mentions, those are simple DataObjects, and that it actually uses the same basic Form used everywhere.
So how does it do validation? Ignoring the customization bits, it uses jquery.validate.min.js, and code like the following:
// Build actions
$actions = new FieldSet(
new FormAction("process", $this->SubmitButtonText)
);
// Do we want to add a clear form.
if($this->ShowClearButton) {
$actions->push(new ResetFormAction("clearForm"));
}
// return the form
$form = new Form( $this, "Form", $fields, $actions, new RequiredFields(array_keys($fieldValidation)));
$form->loadDataFrom($this->failover);
$FormName = $form->FormName();
// Set the Form Name
$rules = $this->array2json($fieldValidationRules);
$messages = $this->array2json($fieldValidation);
// set the custom script for this form
Requirements::customScript(<<<JS
(function($) {
$(document).ready(function() {
$defaults
$("#$FormName").validate({
errorClass: "required",
messages:
$messages
,
rules:
$rules
});
$CustomDisplayRules
});
})(jQuery);
JS
);
It continues to use the jQuery compatible-mode wrapper, because other code might use prototype for more than just form validation.
Here's the documentation on that validate method: http://docs.jquery.com/Plugins/Validation#Validate_forms_like_you.27ve_never_been_validating_before.21
Overall, jQuery's validation is both impressive and kind of scary-huge. I'll have to dig into it a touch more, but it looks easy enough.
The best part about doing this? It feels like I'm running on the future, today. Even the forum module has been rewritten to use jQuery. And I don't have any ugly code at the bottom, or useless JS in every request.
P.S. There's an ugly bug when you edit a posting on this forum with a code block in it. (Or at least when I just edited this post here, now.) It adds a <br> tag to the beginning of every line. It added a second one when I hit save, saw the <br>s in the edited post, and edited it again. Not fun, though easy to fix on my end. (Find/Replace)