0

I want to give my client the ability to visually select a file from one of my file-folders in safecracker. I was thinking of using an embed with {exp:assets:files} loop in there, something along these lines:

{exp:assets:files folder_id='1' kind='image'}
    <li><a href="#" data-url="{url}"><img src="{url}" alt="{filename}"></a></li>
{/exp:assets:files}

Now what would I feed back to the safecracker-form in order for my assets-field in this entry to be updated with the file I just clicked? Should I feed the file's url to a hidden <input> element?

Thanks,

  • Steven

2 Answers 2

1

currently there's no way to do what you want that I can think of, but I like the idea. Seeing as we have Assets 2.1 in development, I'll have a chat with Brandon and we'll see what we can come up with to make you happy.

Cheers, Andris

4
  • 1
    I think implementation-wise this would ideally work by filling an <input type="hidden" name="my_custom_field[id]" value="{asset_id}"> with the file-id. Is that what you were thinking of?
    – Steven
    Commented Feb 19, 2013 at 10:25
  • Steven, this is how it's working at the moment, yeah :) Commented Feb 19, 2013 at 12:54
  • What do you mean? Can I do this already?
    – Steven
    Commented Feb 19, 2013 at 13:03
  • Nope - that's how it's working on my Assets build at the moment :p As soon as I get the remaning stuff for Assets 2.1 in order, you'll be able to do that as well. Commented Feb 19, 2013 at 13:38
0

I think it's probably going to be a bit more complex than that. Assets may be doing that work with JavaScript rather than just routing a selected file to a field.

I would recommend opening up Firebug in Firefox or Developer Tools in Chrome or Safari, and instantiating a full-blown Assets field in your Safecracker template. You can then see:

  • The HTML it generates for the dynamic form field
  • The JavaScript references and any inline script it bundles into the form
  • What happens when you actually select a file and where that's stored until the form is submitted

You'll then have a sense of what you need to reproduce on your end to accomplish your goal.

I've never done this with Assets. We've done it with Matrix, where it's just a matter of adding sets of form fields with a new fieldname convention. I suspect Assets is going to go a little deeper, though.

3
  • I understand that, since version 2.0 however assets also has the ability to do uploads in Safecracker with just a simple html file-input, so I thought there'd be a semi-easy way to do this...
    – Steven
    Commented Feb 12, 2013 at 14:16
  • I wasn't aware of that and it doesn't look like there's much in their docs. The P&T team will have to chime in and top my answer :) Commented Feb 12, 2013 at 14:18
  • Lucky for me they've been known to roam these parts (read: StackExchange is their official support now :) )
    – Steven
    Commented Feb 12, 2013 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.