smalot / bootstrap-datetimepicker

Both Date and Time picker widget based on twitter bootstrap (supports Bootstrap v2 and v3)
http://www.malot.fr/bootstrap-datetimepicker/
Apache License 2.0
3.49k stars 1.65k forks source link

Formatting lost #698

Open Greg85374 opened 6 years ago

Greg85374 commented 6 years ago

Fairly typical project. We have 3 signoffs (using Datepicker) which have to occur in order. Data is read/written to/from a SQL database. Once you use the "remove" option, you lose formatting. . After the OneUp AKA Director signs off, the manager may choose a date between "today" and two weeks in the future. Once the managers date elapses, the employee can sign off. Problem is data is loaded form a db, so the Onchange doesn't help as it is not fired. Once a postback occurs, the time is displayed in the next two datetime pickers

<%--datetimepicker methods--%>

Code Behind: //call from populate and save, and page_load if postabck internal void HandleSignOffLogic() {

        this.txtOneUpSignOff.Attributes.Add("readonly", "readonly");
        this.txtSuperSignOff.Attributes.Add("readonly", "readonly");
        this.txtEmployeeSignOff.Attributes.Add("readonly", "readonly");

        if (this.SurveyStatusID < 3 || this.SurveyStatusID >= 6) /*Needs OneUpManagement Sign-Off,Completed-Queued for Abra*/
        {
            //lock everything
            string script = "$('#dtpOneUpSignOff').datetimepicker('remove'); $('#dtpSuperSignOff').datetimepicker('remove');$('#dtpEmployeeSignOff').datetimepicker('remove');";
           // App_Code.CommonWebCode.RegisterStartupScript(this.Page, "RemoveAllSignOffScripts",script, true);
            this.txtEmployeeSignOff.Attributes.Add("readonly", "readonly");
        }
        else
        {
            string startDate = DateTime.Now.ToShortDateString();
            string endDate = DateTime.Now.ToShortDateString();

            //make sure oneup cannot supply past signoff date
            if (this.SurveyStatusID == 3)
            {
                //prevent super and employee sign off
                this.txtOneUpSignOff.Attributes.Remove("readonly");
                string script = "$('#dtpSuperSignOff').datetimepicker('remove');$('#dtpEmployeeSignOff').datetimepicker('remove');";
                App_Code.CommonWebCode.RegisterStartupScript(this.Page, "RemoveSuperAndEmployeeSignOffScripts", script, true);
                App_Code.CommonWebCode.RegisterStartupScript(this.Page, "OneUpSignOffDateScript", "SetOneUpSignOffDateRange('" + startDate + "','" + endDate + "');", true);
            }
            else if (this.SurveyStatusID == 4)
            {
                //prevent oneup and employee
                this.txtSuperSignOff.Attributes.Remove("readonly");
                string script = "$('#dtpOneUpSignOff').datetimepicker('remove');$('#dtpEmployeeSignOff').datetimepicker('remove');";
               // App_Code.CommonWebCode.RegisterStartupScript(this.Page, "RemoveOneUpAndEmployeeSignOffScripts", script, true);
                endDate = DateTime.Now.AddDays(14).ToShortDateString();
                App_Code.CommonWebCode.RegisterStartupScript(this.Page, "SuperSignOffDateScript", "SetSuperSignOffDateRange('" + startDate + "','" + endDate + "');", true);

            }
            else if (this.SurveyStatusID == 5)
            {
                //prevent oneup and super
                this.txtEmployeeSignOff.Attributes.Remove("readonly");
                string script = "$('#dtpOneUpSignOff').datetimepicker('remove'); $('#dtpSuperSignOff').datetimepicker('remove');";
               // App_Code.CommonWebCode.RegisterStartupScript(this.Page, "RemoveSuperAndOneUpSignOffScripts", script, true);
                App_Code.CommonWebCode.RegisterStartupScript(this.Page, "EmployeeSignOffDateScript", "SetEmployeeSignOffDateRange('" + startDate + "','" + endDate + "');", true);

            }

        }
    }