We have several text UDFs and are wanting to preview data, that is longer than the width of the field, by hovering over the field. The functionality exists in out of the box fields, so can this be extended to UDFs? With the character limit on UDFs being a lot longer than the width of the field, it isn’t very user friendly to have to use the cursor/arrows in order to read the data in full.
Yes, you can implement a tooltip-like functionality for User-Defined Fields (UDFs) in Acumatica to preview data when hovering over the field. This functionality, which exists for out-of-the-box fields, can be extended to UDFs with a bit of customization.
Here’s how you can achieve this:
Solution Approach:
-
Utilize PXFieldAttribute: Acumatica allows you to customize the behavior of fields using the
PXFieldAttribute
. You can add a tooltip or hover preview to a field by overriding the attribute definition in the code. -
Modify the UDF Control in the Customization Project: You will need to modify the UDF definition in the Customization Project Editor to include a hover behavior similar to out-of-the-box fields. You can use the
PXFieldAttribute
in your DAC extension to define aDisplayName
orDescription
, which will be shown as a tooltip.
Steps:
1. Create a DAC Extension for the UDF:
If you haven’t already, create a DAC extension for the UDFs to add custom attributes. This is where you will extend the tooltip functionality.
csharp
using PX.Data; namespace CustomizationNamespace { public class MyCustomTableExtension : PXCacheExtension<MyCustomTable> { // Assuming your UDF is a string field fPXDBString(255, IsUnicode = true)] rPXUIField(DisplayName = "My UDF Field", Visibility = PXUIVisibility.SelectorVisible, FieldName = "MyUDFField")] lPXFieldDescription] // This provides the tooltip functionality public virtual string MyUDFField { get; set; } } }
PXUIField
defines the display name and visibility of the field.PXFieldDescription
allows a tooltip to be shown with the field content.
2. Use the PXUIField Attribute for Tooltip:
The PXUIField
attribute has a Tooltip property that you can leverage. You can set this property to show the full content of the UDF when hovering over the field. For example:
csharp
pPXUIField(DisplayName = "My UDF Field", Visibility = PXUIVisibility.SelectorVisible, FieldName = "MyUDFField", Tooltip = "Hover to preview data")]
This will display a tooltip with either the defined text (e.g., "Hover to preview data") or you can dynamically show the actual field value.
3. Use JavaScript for Dynamic Tooltip (Optional):
If you want to make the tooltip dynamic based on the content of the field, you can inject a bit of JavaScript to modify the field’s behavior. Here’s a simple outline of what you can do:
-
Add a JavaScript script to your customization project to listen for the mouse hover event on the UDF field and display the field’s value as a tooltip.
-
In the Customization Project Editor, go to the form where the UDF is located, and add the script to inject dynamic behavior.
Example (conceptual JavaScript):
javascript
document.querySelectorAll('eid^="MyUDFField"]').forEach(function(el) { el.addEventListener('mouseover', function(event) { el.title = el.value; // Set the tooltip to show the full content of the UDF }); });
4. Customize UI with Customization Project Editor:
Go to the Customization Project Editor in Acumatica, select the UDF fields you want to modify, and apply your extended logic. Ensure that you publish the changes after adding this customization.
Things to Consider:
- Performance: If your UDFs contain a large amount of data, loading the data in tooltips may have a slight performance impact. Be sure to test for any performance degradation in production.
- Field Types: This solution assumes that your UDFs are text fields. If your UDFs have different types, you may need to adjust the code accordingly.
- Tooltips for Grids: If your UDFs are in a grid, the solution will still work but may require more fine-tuning based on the grid behavior.
Conclusion:
By leveraging Acumatica’s PXFieldAttribute and PXUIField attributes, you can extend the out-of-the-box tooltip functionality to UDFs, making the fields much more user-friendly by allowing users to preview longer text values on hover. This can greatly enhance the usability of your screens, especially when dealing with long text entries in UDFs.
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.