Search code examples
acumaticaerp

How to make PXAction and PXUIFieldAttribute.SetEnabled Work


I do not know why my code is not working or something might be missing.

I am trying to do is use PXAction to disable as specific field, when I compile and run this it my browser would just load into infinity.

Thank you guys!

Here is my code

DAC:

 #region RadnomTest
 [PXDBString(20, IsUnicode = true)]
 [PXUIField(DisplayName = "Random Test")]
 public virtual string RadnomTest { get; set; }
 public abstract class radnomTest : BqlString.Field<radnomTest> { }
 #endregion

GRAPH

#region Toggle Readonly
 public PXAction<ClientProfileNames> ReadonlyToggle;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Toggle Read-only")]
protected virtual void readonlyToggle(Events.RowSelected<ClientProfileNames> e)
{
    var row = e.Row;
    PXUIFieldAttribute.SetEnabled<ClientProfileNames.radnomTest>(e.Cache, row, true);

 Actions.PressSave();
}
#endregion

PAGE

<asp:Content ID="cont1" ContentPlaceHolderID="phDS" Runat="Server">
    <px:PXDataSource ID="ds" runat="server" Visible="True" Width="100%" PrimaryView="ClinetInfosMain" TypeName="OnlyForTesting.Graph.Profile.ClientProfileNamesMaint">
        <CallbackCommands>
        </CallbackCommands>
    </px:PXDataSource>
</asp:Content>
<asp:Content ID="cont2" ContentPlaceHolderID="phF" Runat="Server">
    <px:PXFormView ID="form" runat="server" DataSourceID="ds" Style="z-index: 100" Width="100%" DataMember="ClinetInfosMain" TabIndex="2900">
        <Template>
            <px:PXLayoutRule runat="server" StartRow="True" StartColumn="True"/>
            <px:PXTextEdit ID="edRadnomTest" runat="server" AlreadyLocalized="False" DataField="RadnomTest" IsClientControl="True">
            </px:PXTextEdit>
        </Template>
        <AutoSize Container="Window" Enabled="True" MinHeight="200" />
    </px:PXFormView>
</asp:Content>

Solution

  • Field state should be set from the RowSelected event, and not as the result of an action such a button click.

    If you need to set the enabled status based on the value of another field, I would recommend checking the PXUIEnabled attribute which will let you handle this in a declarative fashion: https://asiablog.acumatica.com/2016/11/pxuienabled-and-pxuirequired-attributes.html