When we want to check button or any field’s UI attribute that is Enabled or not. how can we perform it?
I did some research in the source code and it seems you can get a fields attribute in the following way.
cache.GetAttributesOfType<PXUIFieldAttribute>(null, nameof(field)).FirstOrDefault().Enabled;
I also found an extension that does this for you. However, aside for the extension being there, I have not seen it used anywhere in the source code.
using PX.Objects.CN.Common.Extensions;
bool foo = CacheExtensions.GetEnabled<field>(e.Cache, null);
I hope this helps!
Hi
Can you try the below one to get the Disabled / read-only fields of UI.
#region EventHandler
protected void DACName_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
var row = (DACName)e.Row;
if (row != null)
{
string fieldName = String.Empty;
foreach (string field in cache.Fields)
{
var state = cache.GetStateExt(null, field) as PXFieldState;
if (state != null)
{
if (!state.Enabled && state.IsReadOnly && state.Visible)
{
// gettting field Name
fieldName = state.Name;
// your logic....
}
}
}
}
}
#endregion
I hope this helps you.
You can try action.GetEnabled().
it’s working with PXAction but for PXUIField it does not work.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.