Skip to main content
Solved

Truble with dialog

  • December 5, 2025
  • 1 reply
  • 24 views

Forum|alt.badge.img+2

public PXAction<FSEquipment> UpdateHours;
        [PXUIField(DisplayName = Messages.UpdateHours, MapEnableRights = PXCacheRights.Select, MapViewRights = PXCacheRights.Select)]
        [PXButton(DisplayOnMainToolbar = false)]
        public IEnumerable updateHours(PXAdapter adapter)
        {
            if (MaintenanceLogInfo.AskExt(UpdateHoursSetVisible, true) == WebDialogResult.OK)
            {
                DateTime date = MaintenanceLogInfo.Current.Date.GetValueOrDefault();
                decimal hours = MaintenanceLogInfo.Current.Hours.GetValueOrDefault();

                if (date == null)
                {
                    // Acuminator disable once PX1051 NonLocalizableString [Justification]
                    MaintenanceLogInfo.Cache.RaiseExceptionHandling<FSMaintenanceLogInfo.date>(
                        MaintenanceLogInfo.Current,
                        date,
                        new PXSetPropertyException(Messages.DateCannotBeEmpty)
                    );

                    return adapter.Get();
                }

                if (hours < 0)
                {
                    // Acuminator disable once PX1051 NonLocalizableString [Justification]
                    MaintenanceLogInfo.Cache.RaiseExceptionHandling<FSMaintenanceLogInfo.hours>(
                        MaintenanceLogInfo.Current,
                        hours,
                        new PXSetPropertyException(Messages.HoursMustBeGreaterThanZero)
                    );

                    return adapter.Get();
                }
                AddOrUpdateMaintenanceLog(date, hours, false);
            }
            return adapter.Get();
        }

When I enter a value < 0 in the Hours field, keep focus on that field, and click OK, the dialog closes without showing the validation error, even though I confirmed with debugging that the if (hours < 0) block is executed.

How can I prevent the dialog from closing and properly display the validation error when the value is invalid?

 

Best answer by darylbowman

Make the ‘OK’ button conditionally enabled.

 

To disable a dialog button:

  1. Add a PXButton action in code (using the primary DAC type)
  2. Associate the button in ASPX by setting CommandName and CommandSourceID = ds
  3. Set the SyncVisible="True" property on the ASPX button
  4. Set the enable/disable logic in the RowSelected event of the dialog DAC type:
    protected virtual void _(Events.RowSelected<DXSplitFilter> e)
    {
        DXSplitFilter row = e.Row;

        if (row is null) return;

        bool timeSpentEqualsOrig = row.TimeSpentSplit1 + row.TimeSpentSplit2 == row.OrigTimeSpent;

        bool billableTimeSpentEqualsOrig = row.BillableTimeSpentSplit1 + row.BillableTimeSpentSplit2 == row.OrigBillableTimeSpent;

        splitDialogOK.SetEnabled(timeSpentEqualsOrig && billableTimeSpentEqualsOrig);
    }

     

 

1 reply

darylbowman
Captain II
Forum|alt.badge.img+15
  • Answer
  • December 5, 2025

Make the ‘OK’ button conditionally enabled.

 

To disable a dialog button:

  1. Add a PXButton action in code (using the primary DAC type)
  2. Associate the button in ASPX by setting CommandName and CommandSourceID = ds
  3. Set the SyncVisible="True" property on the ASPX button
  4. Set the enable/disable logic in the RowSelected event of the dialog DAC type:
    protected virtual void _(Events.RowSelected<DXSplitFilter> e)
    {
        DXSplitFilter row = e.Row;

        if (row is null) return;

        bool timeSpentEqualsOrig = row.TimeSpentSplit1 + row.TimeSpentSplit2 == row.OrigTimeSpent;

        bool billableTimeSpentEqualsOrig = row.BillableTimeSpentSplit1 + row.BillableTimeSpentSplit2 == row.OrigBillableTimeSpent;

        splitDialogOK.SetEnabled(timeSpentEqualsOrig && billableTimeSpentEqualsOrig);
    }