Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend\Form\Decorator\JavascriptValidator Component Proposal

Proposed Component Name Zend\Form\Decorator\JavascriptValidator
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend\Form\Decorator\JavascriptValidator
Proposers Ricardo Buquet
Zend Liaison TBD
Revision 1.0 - 1 March 2012: Initial Draft. (wiki revision: 15)

Table of Contents

1. Overview

Zend\Form\Decorator\JsAutoValidator is a unobtrusive JavaScript validator that takes into account every (javascript) possible validator rule, and writes down a json with all the information, making available all you need to know to make your own javascript validation.
It also has a built in javascript validator, which can be replaced by your own implementation.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

Zend\Form\Decorator\JsAutoValidator will generate an agnostic json for element validation, filtering and error decoration. This will allow you to use the built in javascript validator or your own implementation with a simple adapter pattern.

  • This component will correctly read the elements validators, filters and error decorators to generate a json with any of these, if present: validator names, parameters, messages variables, messages, errors, filters, error decorators and break chain on failure.
  • This component will optionally read correctly the errors and formErrors decorators in the form and elements, and expose their desired tags.
  • This component will optionally read the filtering parameters for the elements and expose their filter names.
  • This component will allow the user to specify on which event validation should occur (submitting or clicking a submit button)

4. Dependencies on Other Framework Components

  • Zend_Form_Decorator_Abstract
  • Zend_View
  • Zend_View_Helper_HeadScript by default, could be changed by own implementation
  • Zend_View_Helper_InlineScript by default, could be changed by own implementation
  • Zend_Exception
  • Jquery (only the draft will be changed to native javascript)

5. Theory of Operation

The component is added to any Zend_Form

6. Milestones / Tasks

  • Milestone 1: [DONE] design notes will be published here
  • Milestone 2: [DONE] Working prototype checked attached to the proposal (I don't know how to publish into the incubator) supporting use cases #1, #2
  • Milestone 3: [DONE] Unit tests exist, covering 100% of the code.
  • Milestone 4: [DONE] Initial documentation exists.

7. Class Index

  • Zend_Form_Decorator_JsAutoValidation

8. Use Cases

UC-01 Assign decorator through ini file
UC-02 Or using a php file.

And in both UC something like this will be printed in json through the inlineScript view helper.

9. Class Skeletons

This is the class skeletons

]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

Labels:
zend_form zend_form Delete
zend_form_decorator zend_form_decorator Delete
zend_form_decorator_jsautovalidation zend_form_decorator_jsautovalidation Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Mar 04, 2012

    <p>I have added an attachment with a fully working super simple use case for the decorator.<br />
    This example contains the JavascriptValidator.php decorator file, the JavascriptValidator.js companion file and a simple use case.</p>

  2. Mar 08, 2012

    <p>Hi Ricardo,<br />
    there are two problems with this proposal:</p>

    <p>1. If this decorator should be implemented in ZF1 then there is not much time, because:</p>

    <blockquote>
    <p>The plan is for all new code, unit tests and documentation to be ready by 23rd March 2012, peer reviewed by a member of the CR Team and committed to the Subversion repository.</p></blockquote>
    <p><a class="external-link" href="http://zend-framework-community.634137.n4.nabble.com/ZF-1-12-Release-td4425960.html">http://zend-framework-community.634137.n4.nabble.com/ZF-1-12-Release-td4425960.html</a></p>

    <p>2. And in version 2, the decorators may be removed: <a class="external-link" href="http://framework.zend.com/wiki/display/ZFDEV2/RFC+-+Forms">http://framework.zend.com/wiki/display/ZFDEV2/RFC+-+Forms</a></p>

    1. Mar 08, 2012

      <p>Hi Frank!<br />
      Well that's a shame!!!, it's working very nice.<br />
      Maybe when it's defined if ZF2 if it will use decorators or not I could refactor what ever is needed. Anyway this decorator doesnt really need to be a decorator, it could be anything that have access to the form and form elements and their respective validation rules, originally I wrote this code as a Class extending Zend_Form, and then move it to a decorator. Cause I thought that was a better approach.</p>

  3. Mar 08, 2012

    <p>It's a good idea...here are a few of my thoughts:</p>

    <ol>
    <li>would be nicer as a service class that accepts a form validator chain (see ZF2 form proposal)</li>
    <li>add a view helper that consumes the service</li>
    <li>provide hooks to existing form validators such as: <a class="external-link" href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">http://bassistance.de/jquery-plugins/jquery-plugin-validation/</a> (i.e. do not provide a ZF specific implementation)</li>
    <li>documentation on how to build your own hooks to your custom JS validator</li>
    <li>documentation on how to plug it into HTML5 native elements</li>
    </ol>

    1. Mar 09, 2012

      <p>Hi Wil thanks for your comments,</p>

      <p>I really like to make this code better<br />
      1- I will take a look into the proposal that you are suggesting.<br />
      2- Can you give me a hint? I really didn't get you<br />
      3- The hooks parts... I think that if my code can expose all the validation parameters in a json format. It will be very simple to create an adapter pattern for any kind of javascript/library validation. Don't you think?<br />
      4- I started that this afternoon.<br />
      5- mmmm I really didn't think of that, that would be an great feature.</p>

      <p>Beside that<br />
      I also don't know where should I place the javascript file that comes with this decorator. I have created an alias in my virtualhost for the javascript which now i'm placing it inside my php, pointing to my public javascript folder.<br />
      Any suggestion?</p>