I want the StartDate to be only to start from today, past dates selection disable
I want the EndDate only be from the Future but always greater then the Start Date
#region StartDate [PXDBDate()] [PXUIField(DisplayName = "Start Date")] public virtual DateTime? StartDate { get; set; } public abstract class startDate : PX.Data.BQL.BqlDateTime.Field<startDate> { } #endregion
#region EndDate [PXDBDate()] [PXUIField(DisplayName = "End Date")] public virtual DateTime? EndDate { get; set; } public abstract class endDate : PX.Data.BQL.BqlDateTime.Field<endDate> { } #endregion
Best answer by harutyungevorgyan
Hello @anupusefulbi ,
If you want to disable past dates in the calendar UI of an Acumatica screen, you can do that using JavaScript. Just paste the following code inside your .aspx page within a <script type="text/javascript"> tag, like so:
<script type="text/javascript"> // Paste the JavaScript code here (function () { function disablePastDates() { const today = new Date(); today.setHours(0, 0, 0, 0);
Would you mind giving this approach a try? I haven't personally tested it—just sharing an idea
#region StartDate [PXDBDate()] [PXDefault(typeof(AccessInfo.businessDate))] [PXUIField(DisplayName = "Start Date")] [PXUIVerify(typeof(Where<startDate, GreaterEqual<Current<AccessInfo.businessDate>>>), PXErrorLevel.Error, "Start Date cannot be in the past.")] public virtual DateTime? StartDate { get; set; } public abstract class startDate : PX.Data.BQL.BqlDateTime.Field<startDate> { } #endregion
#region EndDate [PXDBDate()] [PXUIField(DisplayName = "End Date")] [PXUIVerify(typeof(Where<endDate, Greater<Current<startDate>>>), PXErrorLevel.Error, "End Date must be greater than Start Date.")] public virtual DateTime? EndDate { get; set; } public abstract class endDate : PX.Data.BQL.BqlDateTime.Field<endDate> { } #endregion
protected void _(Events.FieldVerifying<YourDAC, YourDAC.startDate> e) { if (e.NewValue is DateTime newDate) { if (newDate.Date < PXTimeZoneInfo.Now.Date) { throw new PXSetPropertyException("Start Date cannot be in the past."); } } } Restrict EndDate to be greater than StartDate
protected void _(Events.FieldVerifying<YourDAC, YourDAC.endDate> e) { var row = e.Row; if (row == null || e.NewValue == null) return;
If you want to disable past dates in the calendar UI of an Acumatica screen, you can do that using JavaScript. Just paste the following code inside your .aspx page within a <script type="text/javascript"> tag, like so:
<script type="text/javascript"> // Paste the JavaScript code here (function () { function disablePastDates() { const today = new Date(); today.setHours(0, 0, 0, 0);