attachmentPicker for class field

Hello,

I modified a small application in my Xwiki where i have a class and a picture field. For this picture field i used a custom display macro to show the picture in view mode and select a picture in edit mode. It uses the the attachmentselector macro to select the image. But this have the limitation that i just can upload a new picture and not select an existing one.

How can i use the newer attachmentPicker to update the class property?

Here is my velocity code if it helps you:

{{velocity}}
#if ($type == 'edit')
  {{attachmentSelector className="Event.Code.EventClass" property="picture" filter="png,jpeg,jpg" displayImage="true"/}}
  ##{{attachmentGalleryPicker filter="image/*"/}}
#elseif (($type == 'view') && ($!value!=''))
  [[image:attach:$value|| width="100%"]]
#else
  $value
#end
{{/velocity}}

Thanks

Have you tried https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/FrontendResources/AutoSuggestWidget/#HSuggestAttachments ?

Yeah, thanks. This is exactly what i searched for.
I implemented it now and works like a charm.

{{velocity}}
#if ($type == 'edit')
  #set($name2= ${prefix}+${name})
  #set ($attachmentPickerParams = {
      'name': $name2,
      'value': $value,
      'data-upload-allowed': 'true',
      'data-accept': 'image/'
  })
  {{html wiki="true" clean="false"}}
    #attachmentPicker($attachmentPickerParams)
  {{/html}}
#elseif (($type == 'view') && ($!value!=''))
  [[image:attach:$value|| width="100%"]]
#else
  $value
#end
{{/velocity}}