Integrated HTML Form validation

XNAT 1.6 included an enhancement to make form validation easier.  The goal is to have 95% of form validation be implementable without writing javascript.  Instead, developers should be able to perform basic form validation by adding classes or properties to the individual form elements.

To support this, form submits are monitored via a sequence of javascript (footer.js) and additional form validation is performed based on the properties of the form elements.  By default, XNAT supports a predefined set of new validation mechanisms.

NOTE: The javascript validation is identified after the initial page load.  As such, form elements dynamically added after page load via javascript will not be handled by the integrated form validation.  This is something that should be fixed in the near to medium term.

class='required'
Handles: <INPUT>, <SELECT>, <TEXTAREA>
Any input, select, or textareas which have a class="required" will be required to have a value in order for the form to submit. 
Example: <input name='something' class='required'/>

NOTE: When making a set of radio buttons required, only add the class='required' to one of the radio buttons, the one you want to be focused on if the validation fails.

class='float'
Handles: <INPUT>
Adding the float class to any input field will require any value added to the field to be a valid floating point decimal. 
Example: <input name='something' class='float'/>

class='integer'
Handles: <INPUT>
Adding the integer class to any input field will require any value added to the field to be a valid integer. 
Example: <input name='something' class='integer'/>

class='alphaNumSP'
Handles: <INPUT>
Adding the alphaNumSP class to any input field will require the value entered to be alpha-numeric text (spaces, periods, commas allowed).  No special characters.
Example: <input name='something' class='alphaNumSP'/>

 class='alphaSP'
Handles: <INPUT>
Adding the alphaSP class to any input field will require the value entered to be text (no numbers) (spaces allowed).  No special characters.
Example: <input name='something' class='alphaSP'/>


class='max256'

Handles: <INPUT>
Adding the max256 class to any input field will require the value entered be less then 256 character in length.
Example: <input name='something' class='max256'/>

data-regex
Handles: <INPUT>
Adding a data-regex property to an input type allows the excution of any regex validation.  Simply include the javascript regular expression as the contents of the data-regex tag.  If the input value doesn't validate according to that regex, the form will not submit.
Example: <input name='something' data-regex='^[A-Za-z0-9]+$'/>

data-required-if
Handles: <INPUT>
Often, a form element is only valid if another form field is populated.  I.E. if that checkbox is checked, then this textbox is required.  The data-required-if property can be used to specify a jquery select to find the state of other form elements.  The contents of the data-required-if will be passed into a jquery selector and if it finds matches, then this field is required.  If it doesn't find matches, then this field is not required.
Example: <input id='field1' name='field1' type='radio'/><input name='field2' type='text' data-required-if='#field1:checked'/>

CUSTOM VALIDATION:
Sometimes the integrated validation types are not adequate.  In addition to these pre-specified javascript validation mechanisms, developers can easily add their own form validation.  The integrated form validation javascript contains a method called addValidator(element, object).  Users can add their own validation by inserting a compliant validation object using this method.  The validation object must have a method called 'validate'.  That validate should return true if the check passes validation and false if the check fails validation. 

addValidator (input_element, validation_object);

input_element: The first argument identifies the field being validated.  It can be the html element itself, or the id of the element.
validation_object: The second argument is an object which will handle the actual validation.  The only requirement on this function is that it should have a method called 'validate'.  Optionally, it can include a 'message' property that will be used as a tool top on the validation warning checkmark which will be inserted next to the page element on validation failure.
   {
       message:"some string",
       validate:function(){return true;}
   };

Example:
<script>
var net_note=jq('select.some_time_mm')[0];        
addValidator(net_note,{
    message:"The hours and minutes fields are required because you have select a tracer called VALUE1.",
    validate:function(){     
        var tracer=jq('select.tracer_name').val()          
        var hh=getValueById("$item.getXSIType()/fields/field[name=some_time]/field.hours");     
        var mm=getValueById("$item.getXSIType()/fields/field[name=some_time]/field.minutes");     
        if(tracer=="VALUE1" && (hh.value=="" || mm.value=="")){      
            return false;     
        }          
        return true;    
    }   
});- </script>

$label.name