Skip to content

Commit

Permalink
Validation for dates and check optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
paul_calderon committed Jul 21, 2023
1 parent d1fd5e4 commit 49d45eb
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 139 deletions.
6 changes: 6 additions & 0 deletions App_LocalResources/ExportCSV.ascx.resx
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,10 @@
<data name="plInitialDate.Text" xml:space="preserve">
<value>Initial date</value>
</data>
<data name="customDateMessage.Text" xml:space="preserve">
<value>You must select both or no dates</value>
</data>
<data name="errorDateMessage.Text" xml:space="preserve">
<value>Initial date must be earlier than final date</value>
</data>
</root>
27 changes: 27 additions & 0 deletions DotNetNuke.Modules.UserDefinedTable.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 61 additions & 9 deletions ExportCSV.ascx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,33 @@
<asp:CheckBox ID="cbSystemFields" runat="server" />
</div>
<div class="dnnFormItem">
<dnn:label id="plInitialDate" runat="server" controlname="cbSystemFields" />
<dnn:label id="plInitialDate" runat="server" controlname="txtInitialDate" />
<asp:TextBox ID="txtInitialDate" CssClass="NormalTextBox" runat="server" MaxLength="200"
Width="300" />
Width="300" onchange="TriggerChanges();" />
</div>
<div>

</div>
<div class="dnnFormItem">
<dnn:label id="plFinalDate" runat="server" controlname="cbSystemFields" />
<dnn:label id="plFinalDate" runat="server" controlname="txtFinalDate" />
<asp:TextBox ID="txtFinalDate" CssClass="NormalTextBox" runat="server" MaxLength="200"
Width="300" />
Width="300" onchange="TriggerChanges();" />
</div>
<div class="dnnFormItem">
<dnn:label id="plDatesValidator" value="" runat="server" controlname="cvtxtStartDate" />
<asp:CompareValidator id="compareValidatorDates" runat="server"
ControlToCompare="txtInitialDate" cultureinvariantvalues="true"
display="Dynamic" enableclientscript="true"
ControlToValidate="txtFinalDate"
type="Date" Operator="GreaterThanEqual"
CssClass="validator-error" resourcekey="errorDateMessage" >
</asp:CompareValidator>
<asp:CustomValidator id="CustomValidatorDates"
ControlToValidate="txtInitialDate"
ClientValidationFunction="ValidateDatesClient"
Display="Dynamic"
runat="server"
resourcekey="customDateMessage" CssClass="validator-error"/>
</div>
<ul class="dnnActions dnnClear">
<li>
Expand All @@ -50,9 +69,42 @@

<script>
$(function () {
$("#<%= txtInitialDate.ClientID %>").attr("readonly", "readonly");
$("#<%= txtInitialDate.ClientID %>").datepicker({ dateFormat: "yy/mm/dd" });
$("#<%= txtFinalDate.ClientID %>").attr("readonly", "readonly");
$("#<%= txtFinalDate.ClientID %>").datepicker({ dateFormat: "yy/mm/dd" });
});
$("#<%= txtInitialDate.ClientID %>").datepicker({
dateFormat: "yy/mm/dd",
showButtonPanel: true,
closeText: 'Clear',
onClose: function () {
var event = arguments.callee.caller.caller.arguments[0];
if ($(event.delegateTarget).hasClass('ui-datepicker-close')) {
$(this).val('');
TriggerChanges();
}
}
});
$("#<%= txtFinalDate.ClientID %>").datepicker({
dateFormat: "yy/mm/dd",
showButtonPanel: true,
closeText: 'Clear',
onClose: function () {
var event = arguments.callee.caller.caller.arguments[0];
if ($(event.delegateTarget).hasClass('ui-datepicker-close')) {
$(this).val('');
TriggerChanges();
}
}
});
});
function TriggerChanges() {
ValidatorValidate(document.getElementById('<%= CustomValidatorDates.ClientID %>'));
}
function ValidateDatesClient(source, arguments) {
if (($("#<%= txtInitialDate.ClientID %>").val().length == 0 && $("#<%= txtFinalDate.ClientID %>").val().length == 0) || ($("#<%= txtInitialDate.ClientID %>").val().length > 0 && $("#<%= txtFinalDate.ClientID %>").val().length > 0)) {
arguments.IsValid = true;
} else {
arguments.IsValid = false;
}
}
</script>
5 changes: 4 additions & 1 deletion ExportCSV.ascx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void Page_Load(object sender, EventArgs e)
cboFolders.Items.Add(folderItem);
}

txtInitialDate.Attributes.Add("readonly", "readonly");
txtFinalDate.Attributes.Add("readonly", "readonly");

var moduleController = new ModuleController();
var objModule = moduleController.GetModule(_moduleId, TabId, false);
if (objModule != null)
Expand Down Expand Up @@ -159,7 +162,7 @@ void ExportData(string folder, string strFileName, string delimiter, string init
{
DataSet ds;

if(initialDate.Length>0 && finalDate.Length > 0)
if(!string.IsNullOrEmpty(initialDate) && !string.IsNullOrEmpty(finalDate))
{
CultureInfo provider = CultureInfo.InvariantCulture;
string format = "yyyy/MM/dd";
Expand Down
Loading

0 comments on commit 49d45eb

Please sign in to comment.