Revision: 2209
http://mrbs.svn.sourceforge.net/mrbs/?rev=2209&view=rev
Author: cimorrison
Date: 2011-12-21 22:18:04 +0000 (Wed, 21 Dec 2011)
Log Message:
-----------
Fixed the Ajax checking so that it can cope with array fields consisting of
multiple inputs, which will arise when the rooms field is disabled, eg
<input type="hidden" name="rooms[]" value="1">
<input type="hidden" name="rooms[]" value="2">
etc.
Modified Paths:
--------------
mrbs/trunk/web/Themes/default/header.inc
Modified: mrbs/trunk/web/Themes/default/header.inc
===================================================================
--- mrbs/trunk/web/Themes/default/header.inc 2011-12-21 17:07:21 UTC (rev
2208)
+++ mrbs/trunk/web/Themes/default/header.inc 2011-12-21 22:18:04 UTC (rev
2209)
@@ -682,7 +682,9 @@
function getFormValue(formInput)
{
var value;
- <?php // Scalar parameters (two types - checkboxes and the rest) ?>
+ <?php
+ // Scalar parameters (three types - checkboxes, radio buttons and the
rest)
+ ?>
if (formInput.attr('name').indexOf('[]') == -1)
{
if (formInput.filter(':checkbox').length > 0)
@@ -698,23 +700,27 @@
value = formInput.val();
}
}
- <?php // Array parameters (two types - checkboxes and the rest) ?>
+ <?php
+ // Array parameters (two types - checkboxes and the rest, which could be
+ // <select> elements or else multiple ordinary inputs with a *[] name
+ ?>
else
{
value = [];
- if (formInput.filter(':checkbox').length > 0)
- {
- formInput.each(function(index) {
- if ($(this).is(':checked'))
+ formInput.each(function(index) {
+ if ((formInput.filter(':checkbox').length == 0) ||
$(this).is(':checked'))
+ {
+ var thisValue = $(this).val();
+ if ($.isArray(thisValue))
{
+ $.merge(value, thisValue);
+ }
+ else
+ {
value.push($(this).val());
}
- });
- }
- else
- {
- value = formInput.val();
- }
+ }
+ });
}
return value;
}
@@ -744,22 +750,22 @@
return;
}
+ <?php
// Load the params object with the values of all the form fields that
are not
// disabled and are not submit buttons of one kind or another
- form.find('[name]').not(':disabled, [type="submit"], [type="button"],
[type="image"]').each(function() {
+ ?>
+ var relevantFields = form.find('[name]').not(':disabled,
[type="submit"], [type="button"], [type="image"]');
+ relevantFields.each(function() {
+ <?php
+ // Go through each of the fields and if we haven't got the value
for a name
+ // then go and get it. (Remember that arrays can give more than
one field
+ // with the same name
+ ?>
var fieldName = $(this).attr('name');
if (params[fieldName] === undefined)
{
- params[fieldName] = getFormValue($(this));
+ params[fieldName] = getFormValue(relevantFields.filter('[name='
+ fieldName.replace('[', '\\[').replace(']', '\\]') + ']'))
}
- else
- {
- if ($.isArray(params[fieldName]))
- {
- var value = getFormValue($(this));
- $.merge(params[fieldName], value);
- }
- }
});
<?php
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Write once. Port to many.
Get the SDK and tools to simplify cross-platform app development. Create
new or port existing apps to sell to consumers worldwide. Explore the
Intel AppUpSM program developer opportunity. appdeveloper.intel.com/join
http://p.sf.net/sfu/intel-appdev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits