Commit r2400: https://sourceforge.net/p/mrbs/code/2400/
------------------------------------------------------------------------
r2400 | cimorrison | 2012-09-09 14:56:24 +0100 (Sun, 09 Sep 2012) | 1 line
Changed paths:
M /mrbs/trunk/web/edit_entry.php
M /mrbs/trunk/web/js/edit_entry.js.php
Moved some JavaScript out of edit_entry.php into edit_entry.js.php
------------------------------------------------------------------------
Index: mrbs/trunk/web/js/edit_entry.js.php
===================================================================
--- mrbs/trunk/web/js/edit_entry.js.php (revision 2399)
+++ mrbs/trunk/web/js/edit_entry.js.php (revision 2400)
@@ -16,6 +16,80 @@
$is_admin = (authGetUserLevel($user) >= $max_level);
+// Set the error messages to be used for the various fields. We do this
twice:
+// once to redefine the HTML5 error message and once for JavaScript alerts,
for those
+// browsers not supporting HTML5 field validation.
+?>
+function validationMessages()
+{
+ <?php
+ // First of all create a property in the vocab object for each of the
mandatory
+ // fields. These will be the 'name' and 'rooms' fields and any other
fields
+ // defined by the config variable $is_mandatory_field
+ ?>
+ validationMessages.vocab = {};
+ validationMessages.vocab['name'] = '';
+ validationMessages.vocab['rooms'] = '';
+ <?php
+ foreach ($is_mandatory_field as $key => $value)
+ {
+ list($table, $fieldname) = explode('.', $key, 2);
+ if ($table == 'entry')
+ {
+ ?>
+ validationMessages.vocab['<?php echo escape_js(VAR_PREFIX . $fieldname)
?>'] = '';
+ <?php
+ }
+ }
+
+ // Then (a) fill each of those properties with an error message and (b)
redefine
+ // the HTML5 error message
+ ?>
+ for (var key in validationMessages.vocab)
+ {
+ validationMessages.vocab[key] = $("label[for=" + key + "]").html();
+ validationMessages.vocab[key] = '"' +
validationMessages.vocab[key].replace(/:$/, '') + '" ';
+ validationMessages.vocab[key] += '<?php echo
escape_js(get_vocab("is_mandatory_field")) ?>';
+
+ var field = document.getElementById(key);
+ if (field.setCustomValidity && field.willValidate)
+ {
+ <?php
+ // We define our own custom event called 'validate' that is triggered on
the
+ // 'change' event for checkboxes and select elements, and the 'input'
even
+ // for all others. We cannot use the change event for text input
because the
+ // change event is only triggered when the element loses focus and we
want the
+ // validation to happen whenever a character is input. And we cannot
use the
+ // 'input' event for checkboxes or select elements because it is not
triggered
+ // on them.
+ ?>
+ $(field).bind('validate', function(e) {
+ <?php
+ // need to clear the custom error message otherwise the browser will
+ // assume the field is invalid
+ ?>
+ e.target.setCustomValidity("");
+ if (!e.target.validity.valid)
+ {
+
e.target.setCustomValidity(validationMessages.vocab[$(e.target).attr('id')]);
+ }
+ });
+ $(field).filter('select, [type="checkbox"]').bind('change', function(e) {
+ $(this).trigger('validate');
+ });
+ $(field).not('select, [type="checkbox"]').bind('input', function(e) {
+ $(this).trigger('validate');
+ });
+ <?php
+ // Trigger the validate event when the form is first loaded
+ ?>
+ $(field).trigger('validate');
+ }
+ }
+}
+
+
+<?php
// do a little form verifying
?>
function validate(form)
Index: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php (revision 2399)
+++ mrbs/trunk/web/edit_entry.php (revision 2400)
@@ -1130,81 +1130,8 @@
echo "areas[${area['id']}]['$key'] = $value;\n";
}
}
-
-
-// Set the error messages to be used for the various fields. We do this
twice:
-// once to redefine the HTML5 error message and once for JavaScript alerts,
for those
-// browsers not supporting HTML5 field validation.
?>
-function validationMessages()
-{
- <?php
- // First of all create a property in the vocab object for each of the
mandatory
- // fields. These will be the 'name' and 'rooms' fields and any other
fields
- // defined by the config variable $is_mandatory_field
- ?>
- validationMessages.vocab = {};
- validationMessages.vocab['name'] = '';
- validationMessages.vocab['rooms'] = '';
- <?php
- foreach ($is_mandatory_field as $key => $value)
- {
- list($table, $fieldname) = explode('.', $key, 2);
- if ($table == 'entry')
- {
- ?>
- validationMessages.vocab['<?php echo escape_js(VAR_PREFIX . $fieldname)
?>'] = '';
- <?php
- }
- }
- // Then (a) fill each of those properties with an error message and (b)
redefine
- // the HTML5 error message
- ?>
- for (var key in validationMessages.vocab)
- {
- validationMessages.vocab[key] = $("label[for=" + key + "]").html();
- validationMessages.vocab[key] = '"' +
validationMessages.vocab[key].replace(/:$/, '') + '" ';
- validationMessages.vocab[key] += '<?php echo
escape_js(get_vocab("is_mandatory_field")) ?>';
-
- var field = document.getElementById(key);
- if (field.setCustomValidity && field.willValidate)
- {
- <?php
- // We define our own custom event called 'validate' that is triggered on
the
- // 'change' event for checkboxes and select elements, and the 'input'
even
- // for all others. We cannot use the change event for text input
because the
- // change event is only triggered when the element loses focus and we
want the
- // validation to happen whenever a character is input. And we cannot
use the
- // 'input' event for checkboxes or select elements because it is not
triggered
- // on them.
- ?>
- $(field).bind('validate', function(e) {
- <?php
- // need to clear the custom error message otherwise the browser will
- // assume the field is invalid
- ?>
- e.target.setCustomValidity("");
- if (!e.target.validity.valid)
- {
-
e.target.setCustomValidity(validationMessages.vocab[$(e.target).attr('id')]);
- }
- });
- $(field).filter('select, [type="checkbox"]').bind('change', function(e) {
- $(this).trigger('validate');
- });
- $(field).not('select, [type="checkbox"]').bind('input', function(e) {
- $(this).trigger('validate');
- });
- <?php
- // Trigger the validate event when the form is first loaded
- ?>
- $(field).trigger('validate');
- }
- }
-}
-
-
// set up some global variables for use by OnAllDayClick().
var old_start, old_end;
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits