kelvint 2002/12/04 16:21:45 Modified: contributions/javascript/queryConstructor luceneQueryConstructor.js Log: Trims field values to address any validation problems with whitespace. Revision Changes Path 1.4 +18 -1 jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js Index: luceneQueryConstructor.js =================================================================== RCS file: /home/cvs/jakarta-lucene-sandbox/contributions/javascript/queryConstructor/luceneQueryConstructor.js,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- luceneQueryConstructor.js 3 Dec 2002 11:48:17 -0000 1.3 +++ luceneQueryConstructor.js 5 Dec 2002 00:21:45 -0000 1.4 @@ -52,7 +52,7 @@ else if(subElement.type == "radio") { // radio button elements often have the same element name, - // so ensure we have the right one + // so ensure we have the right one if(subElement.checked) { subElementValue = subElement.value; @@ -101,6 +101,8 @@ function addFieldWithModifier(query, modifier, field, fieldValue) { + fieldValue = trim(fieldValue); + if(query.value.length == 0) { query.value = modifier + '(' + field + ':(' + fieldValue + '))'; @@ -109,4 +111,19 @@ { query.value = query.value + ' ' + modifier + '(' + field + ':(' + fieldValue + '))'; } +} + +function trim(inputString) { + if (typeof inputString != "string") { return inputString; } + + var temp = inputString; + + // Replace whitespace with a single space + var pattern = /\s/ig; + temp = temp.replace(pattern, " "); + + // Trim + pattern = /^(\s*)([\w\W]*)(\b\s*$)/; + if (pattern.test(temp)) { temp = temp.replace(pattern, "$2"); } + return temp; // Return the trimmed string back to the user }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>