restrict file type selection for document picker

cancel
Showing results for 
Search instead for 
Did you mean: 
Active Member II

restrict file type selection for document picker

Hi Team,

I have created one association in datalist content model as per below:

<associations>
				<association name="classi:picture">
					<title>Picture</title>
					<source>
						<mandatory>false</mandatory>
						<many>true</many>
					</source>
					<target>
						<class>cm:content</class>
						<mandatory>false</mandatory>
						<many>false</many>
					</target>
				</association>
</associations>

Document picker is working fine.

I want to allow only png and jpeg files to select.

I have tried the way suggested in https://blog.arvixe.com/add-new-form-validation-handler/ 

if (field.type == "hidden") {
        var fileName = field.value;
}

I'm getting attached file noderef as an output.

How to get associated file name?

Thanks,

Hardik

1 Reply
Master

Re: restrict file type selection for document picker

You cannot get any more meaningful data from the value in a validation handler within the client-side JavaScript code. You could perform a ReST call to the backend to resolve the value to the node data including mimetype / extension, but ReST calls being asynchronous, that would decouple you from the validation handler flow of execution and you could not influence the result of the validation anymore. There is technically already a parameter that can be used to restrict which elements can be selected in document pickers, and it is even supported by the default client-side picker component, but the default association form control provides no means to specify that option via the control parameters. You would have to create a custom variant of the association control template to pass that along - I have done so in two customer projects and it works quite well.