I have a business requirement where certain fields with specific unique names must always be present in either rows or columns (at least in one of them). I'm looking for guidance on how to implement this validation.
Use Case:
We need to ensure that a specific field (e.g., a field with uniqueName "requiredField") is always displayed in the pivot table, either in rows or columns, and users should not be able to remove it completely from both areas.
Possible Approaches I'm Considering:
Pre-configure and Lock Field Position:
Validation on Field Removal:
Questions:
Hello, Taehong!
Thank you for your question.
Kindly note that it is not possible to prevent some fields from being removed from the slice using our built-in Field List control. For such use cases, we recommend creating your own Field List control.
Please find detailed answers to your questions below:
1) Is there a built-in way to mark certain fields as "required" in the pivot configuration?
In Flexmonster, it is not possible to set some fields as required out of the box.
2) Can we hook into events before a field is removed to validate and potentially cancel the action?
There are no Flexmonster events that are triggered on minor changes in the Field List. It is possible to use DOM events and observers to adjust the behavior of our built-in UI controls, but such low-level interventions are not recommended and may lead to unexpected behavior.
3) Is it possible to disable/hide specific fields in the Field List while keeping them active in rows/columns?
No, our component is designed to show all the fields in the Field List.
4) What would be the recommended approach to implement this requirement?
For the described use case, we recommend creating your own Field List control and using our events and API calls to apply all the changes to Flexmonster.
Here is the JSFiddle to illustrate the idea: https://jsfiddle.net/flexmonster/76r9cv0L/.
You can find the detailed instructions on creating a custom Field List control in the following guide: https://www.flexmonster.com/doc/creating-a-custom-ui-control-or-view/#creating-custom-field-list.
For your use case, we also suggest switching off dragging on the grid and updating the context menu, so users won't be able to remove the field by bypassing the Field List. Here is the example of how to remove the "Remove field" tab from the context menu: https://jsfiddle.net/flexmonster/gbuvksq3/.
Hope you will find our answer helpful. Don't hesitate to contact us if you need our further assistance with implementing a custom Field List control.
Kind regards,
Solomiia
Hello, Taehong!
Hope you are doing well.
Our team is wondering if you had some time to check our previous response about making some measures required in the Field List. Could you please let us know if the suggested approach of creating your own Field List control works well for you?
Looking forward to hearing from you.
Kind regards,
Solomiia
The suggested approach cannot fully meet our requirements, so we will need to change the plan.
Hello, Taehong!
Thank you for your reply.
Feel free to contact us if you decide to revisit the custom field list implementation or if any other questions arise.
Best regards,
Maksym
I was searching for a similar concept and wanted to share that this concept is something that would be very useful for us as well.
We need to be able to require a filter is always added to a specific view and prevent it from being removed. We can create a custom filter popup to prevent removing all values but making the field required is much more difficult. Currently we don't have a great way to do this and while we can rebuild the Field List control internally to support this, rebuilding this is a lot of work and then we are forced to keep it up to date with any changes.
Is there any possibility that you add support for "required" fields?
Thanks,
Brian
Hello, Brian!
Thank you for reaching out to us.
Kindly note that it is not possible to make the specific field required in the current version of Flexmonster. Our team has added your request to our Customers' Wishlist and will consider implementing the required field functionality in the next major version of the component.
For now, we recommend the following workaround to achieve the desired behavior:
1) Disable drag-n-drop so the user cannot remove the field directly from the grid: https://www.flexmonster.com/doc/grid-options/#enable-or-disable-dragging.
2) Update the context menu so users won't be able to remove the field by bypassing the Field List: https://jsfiddle.net/flexmonster/gbuvksq3/.
2a) Create your custom Field List as described in the guide: https://www.flexmonster.com/doc/creating-a-custom-ui-control-or-view/#creating-custom-field-list
2b) Customize the existing Field List using DOM events, e.g., to make the Apply button disabled when the field is removed from the view. Here is an example of how to disable the Field List Apply button on a certain condition: https://jsfiddle.net/flexmonster/n7qg2rdu/.
Hope you will find our answer helpful.
Kind regards,
Solomiia