Expand my Community achievements bar.

SOLVED

how to filter extensions

Avatar

Level 4

Hi,

I have a pathfield, i need to limit the type of the files to .jpeg.

I can't find the right property.

Thanks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Simple approach would be to use regex. Please use this code and keep all extension you want or add or remove

regex :/\.(png|jpg|jpeg)$/, regexText : "Please choose an correct file"

View solution in original post

5 Replies

Avatar

Level 10

See the reference doc

ttps://docs.adobe.com/content/docs/en/cq/5-6-1/widgets-api/?class=CQ.form.PathField

Avatar

Level 4

Yes but i cannot find the property

I have tried with linkPattern but doesn't work

Avatar

Level 10

ANother way to perform this use case is to write a custom predicate. See this community article:

http://wemcode.wemblog.com/custom-predicate-for-pathfield

Avatar

Correct answer by
Level 10

Simple approach would be to use regex. Please use this code and keep all extension you want or add or remove

regex :/\.(png|jpg|jpeg)$/, regexText : "Please choose an correct file"

Avatar

Administrator

Hi 

Please go through the documentation of "CQ.form.PathField",

Link:- https://docs.adobe.com/docs/en/cq/5-6/widgets-api/index.html?class=CQ.form.PathField

You can use :

regex :

linkPattern : String

A pattern to format links after selection in the browse dialog (using CQ.Util.patchText). This is used when only a tr...

parLinkPattern : String

A pattern to format links after selection of a paragraph in the browse dialog (using CQ.Util.patchText). This only ap...

 

As mentioned by Scott, you would need to write custom pathfield, 

Pathfield has a property called predicate which can be used for filtering. You can create and register a custom predicate that returns false for the paths you don't want to be visible in the the dialog. The name of the custom predicate can then be passed to the config of pathfield.

You can find information here : http://wemcode.wemblog.com/custom-predicate-for-pathfield

For more on predicates, the following links can be referred :

http://www.wemblog.com/2013/04/how-to-create-custom-query-predicate-in.html

http://labs.sixdimensions.com/blog/2013-07-10/custom-predicateevaluators-or-how-i-learned-stop-worry...

 

I hope this would help you.

Thanks and Regards

Kautuk Sahni



Kautuk Sahni