Skip to content

Commit

Permalink
Reparse formatted value before sending to server. Resolves #75.
Browse files Browse the repository at this point in the history
  • Loading branch information
programcsharp committed Oct 27, 2016
1 parent c3af5fb commit ac8da0b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Build/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.5.19")]
[assembly: AssemblyFileVersion("1.5.19")]
[assembly: AssemblyVersion("1.5.20")]
[assembly: AssemblyFileVersion("1.5.20")]
//[assembly: AssemblyInformationalVersion("1.4.5-editlyalpha2")]
59 changes: 46 additions & 13 deletions Griddly/Scripts/griddly.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,9 @@
if (!dontHide)
filter.find(".filter-trigger").popover("hide");

var val = trimToNull(content.find("input").first().val());
var val = trimToNull(this.getCleanedValue(content.find("input").first().val(), dataType));

content.find("input").first().val(val)

if (val != null)
{
Expand All @@ -577,8 +579,11 @@
}
else if (filter.hasClass("griddly-filter-range"))
{
var val = trimToNull(content.find("input").first().val());
var valEnd = trimToNull(content.find("input").last().val());
var val = trimToNull(this.getCleanedValue(content.find("input").first().val(), dataType));
var valEnd = trimToNull(this.getCleanedValue(content.find("input").last().val(), dataType));

content.find("input").first().val(val)
content.find("input").last().val(valEnd)

if (val != null && valEnd != null)
display = this.getFormattedValue(val, dataType) + " - " + this.getFormattedValue(valEnd, dataType);
Expand Down Expand Up @@ -963,25 +968,53 @@
this.refresh(true);
},

getFormattedValue: function (val, dataType)
getCleanedValue: function (val, dataType)
{
switch (dataType)
{
case "Integer":
{
val = String(val).replace(/[^0-9]/g, "")
val = String(val).replace(/[^0-9-]/g, "")

val = parseInt(val);
if (val.length > 1)
val = val.substr(0, 1) + val.substr(1).replace(/-/g, "");
else if (val == '-')
return null;

if (!isFinite(val))
val = null;
return val;
case "Decimal":
case "Currency":
//case "Percent":
val = String(val).replace(/[^0-9,.-]/g, "").replace(/,/g, "");

return val;
}
if (val.length > 1)
val = val.substr(0, 1) + val.substr(1).replace(/-/g, "");
else if (val == '-')
return null;

return val;
case "Date":
return String(val).replace(/[^0-9a-zA-Z-\/]/g, "");
default:
return val;
}
},

getFormattedValue: function (val, dataType)
{
val = this.getCleanedValue(val, dataType);

switch (dataType)
{
case "Integer":
val = parseInt(val);

if (!isFinite(val))
val = null;

return val;
case "Decimal":
case "Currency":
//case "Percent":
val = String(val).replace(/[^0-9,.-]/g, "").replace(/,/g, "").replace(/\$/g, "");

// TODO: filter down to one decimal point
// TODO: filter out non numerics
Expand Down Expand Up @@ -1019,7 +1052,7 @@

return val;
case "Date":
val = parseForValidDate(String(val).replace(/[^0-9a-zA-Z-\/]/g, ""));
val = parseForValidDate(val);

if (val == null || !isFinite(val))
return null;
Expand Down

0 comments on commit ac8da0b

Please sign in to comment.