angular-patternfly icon indicating copy to clipboard operation
angular-patternfly copied to clipboard

Add support for validations to pfFilterFields (filterType: text)

Open vbusch opened this issue 7 years ago • 5 comments

Using pfFilter, and would like to be able to add validation to a filterType: 'text' field. Either be able to add a custom directive or pfValidation to pfFilter.fields

Our use case is, any value that is a legal regular expression is valid.

vbusch avatar Sep 18 '18 12:09 vbusch

Hi @vbusch, can you please provide a real world example of the type of validation(s) you are looking for? Thanks, it will help me understand what you are looking for. Thanks, Dave

dtaylor113 avatar Sep 18 '18 13:09 dtaylor113

@dtaylor113, we are using the filter to filter a very large list(pf-list-view) of potentially 1000,000 items. We provide them 2 ways to filter. The first is by type, and we are using filterType=select, which works great.

They also want to be able to filter by name. And in order for it to be flexible enough, we need to allow them to search for 'queueA*' or 'queue*small', which would return queueA1, queueA2, queue1small, queue2small etc.

The actual validation we are using on the name is ensuring "new RegExp(filter.value)" doesn't throw an exception. If they enter something like '**A', or any value that the RegExp can't handle, we want the user to receive a validation exception in the normal fashion (input field, outlined in red, with an error message).

vbusch avatar Sep 18 '18 14:09 vbusch

Hi @vbusch, thank you for the example. Can you provide a link to some code illustrating how/where you use "new RegExp(filter.value)"? -thanks

dtaylor113 avatar Sep 18 '18 14:09 dtaylor113

@dtaylor113 I would like to add a validator to line 249 in https://github.com/vbusch/enmasse/blob/console-1626/agent/www/components/addresses/addresses_ctrl.js#L243-L262

The current validation is: https://github.com/vbusch/enmasse/blob/console-1626/agent/www/components/addresses/addresses_ctrl.js#L213-L219

The html can be found https://github.com/vbusch/enmasse/blob/console-1626/agent/www/components/addresses/addresses.html

Let me know, if you would like me to extract the code into something easier to run.

vbusch avatar Sep 18 '18 15:09 vbusch

Hi @vbusch, I see your HTML is structured as:

<div pf-toolbar id="exampleToolbar" config="toolbarConfig">

Which indicates that you are using the older angular-patternfly v3. The current version of angular-patternfly is v4 where we have changed all attribute directives to component tags (see Angular PatternFly 4 Migration Guide: Directive to Component Re-factor

Unfortunately, we do not have the filter validation you are looking for. We could possibly investigate adding it to angular-patternfly v4, but it is unlikely we would be able to add it to the older angular-patternlfy v3.

You could look into customizing the angular-patternfly v3 Filter components and add the validation you require. The v3 filter components are located here. You could copy the source code into your own custom package. It would require adding classes hasError and help-block, and form field $error processing like I recently added here. You would probably need to add it to v3 FilterFields html.

HTH, Dave

dtaylor113 avatar Sep 18 '18 19:09 dtaylor113