- // get the hash from a javascript function
- if (typeof(val_hash) == 'function') {
- val_hash = val_hash(formname);
- } else if (typeof(val_hash) == 'undefined') {
- var el;
- // get hash from a global js variable
- if (typeof(document.validation) != 'undefined') {
- val_hash = document.validation;
- // get hash from a element by if of validation
- } else if (el = document.getElementById('validation')) {
- val_hash = el.innerHTML;
- val_hash = val_hash.replace(new RegExp('<', 'ig'),'<');
- val_hash = val_hash.replace(new RegExp('>', 'ig'),'>');
- val_hash = val_hash.replace(new RegExp('&','ig'),'&');
- // read hash from <input name=foo validation="">
- } else {
- var order = new Array();
- var str = '';
- var yaml = form.getAttribute('validation');
- if (yaml) {
- if (m = yaml.match('^( +)')) yaml = yaml.replace(new RegExp('^'+m[1], 'g'), ''); //unindent
- yaml = yaml.replace(new RegExp('\\s*$',''),'\n'); // add trailing
- str += yaml;
- }
- var m;
- for (var i = 0; i < form.elements.length; i ++) {
- var name = form.elements[i].name;
- var yaml = form.elements[i].getAttribute('validation');
- if (! name || ! yaml) continue;
- yaml = yaml.replace(new RegExp('\\s*$',''),'\n'); // add trailing
- yaml = yaml.replace(new RegExp('^(.)','mg'),' $1'); // indent all
- yaml = yaml.replace(new RegExp('^( *[^\\s&*\\[\\{])',''),'\n$1'); // add newline
- str += name +':' + yaml;
- order[order.length] = name;
- }
- if (str) val_hash = str + "group order: [" + order.join(', ') + "]\n";
- }
- }
- if (typeof(val_hash) == 'string') {
- if (! document.yaml_load) return;
- document.hide_yaml_errors = (! document.show_yaml_errors);
- if (location.search && location.search.indexOf('show_yaml_errors') != -1)
- document.hide_yaml_errors = 0;
- val_hash = document.yaml_load(val_hash);
- if (document.yaml_error_occured) return;
+ if (typeof(val_hash) == 'function') {
+ val_hash = val_hash(formname);
+ } else if (typeof(val_hash) == 'undefined') {
+ var el;
+ if (typeof(document.validation) != 'undefined') {
+ val_hash = document.validation;
+ } else if (el = document.getElementById('validation')) {
+ val_hash = el.innerHTML.replace(/</ig,'<').replace(/>/ig,'>').replace(/&/ig,'&');
+ } else {
+ var order = [];
+ var str = '';
+ var yaml = form.getAttribute('validation');
+ if (yaml) {
+ if (m = yaml.match(/^( +)/)) yaml = yaml.replace(new RegExp('^'+m[1], 'g'), '');
+ yaml = yaml.replace(/\s*$/,'\n');
+ str += yaml;
+ }
+ var m;
+ for (var i = 0; i < form.elements.length; i++) {
+ var name = form.elements[i].name;
+ var yaml = form.elements[i].getAttribute('validation');
+ if (! name || ! yaml) continue;
+ yaml = yaml.replace(/\s*$/,'\n').replace(/^(.)/mg,' $1').replace(/^( *[^\s&*\[\{])/,'\n$1');
+ str += name +':' + yaml;
+ order.push(name);
+ }
+ if (str) val_hash = str + "group order: [" + order.join(', ') + "]\n";