assets selection

I got a field with this:

'label' => 'Imagen',
'type' => 'file',
'accept' => 'jpg|gif|png'

How can I let the user select an asset instead of showing a file field?
Also, is there a way to show a preview of the image right next to the it?



  • edited 9:09AM
    If the field name ends with "image" or "img" then FUEL will automatically create both a file upload and image select field for that field. You can overwrite that in your form_fields method though. The key to getting the asset select window is to add the class "asset_select" followed by the folder name (if it isn't the "images" folder). Below is a link to a list of special CSS classes you can add to your fields that will give them some extra functionality.
  • edited 9:09AM
    How can I set more that one class? tried "select_assets,multifile" also array('select_assets', 'multifile') but it didnt work.
    Also, Ive tried setting a field type as multifile but in database I only see the first selected file. Do I have to use on_after_save to parse the array of files manually?
  • edited 9:09AM
    For multiple classes try "multifile select_assets" (order matters). The "select_assets" class can pass a second class argument as the folder you want to select from (e.g. "select_assets images") so "select_assets multifile" would actually be that argument for the select assets so it's best to switch it.

    With regards to your second question, yes, you will need to use on_after_save to handle the files.
  • edited 9:09AM
    I'm having trouble getting the asset field to use my 'pdf' folder.

    The column in the database is called 'promo_asset'. In my form_fields() function I have:

    $fields['promo_asset']['type'] = 'asset';
    $fields['promo_asset']['class'] = 'asset_select pdf'; /* I have also tried 'select_assets pdf' */
    The asset field is still only letting me select images :(

    Also, is there a way to change the text on the "Select Image" button to "Select pdf" or will this happen when I get the field setup correctly?

  • edited 9:09AM
    If you are using 1.0, try the following instead of using the class:
    $fields['promo_asset']['folder'] = 'pdf';
    The folder must also be writable.
  • edited 9:09AM
    Thanks! Worked like a charm :)
Sign In or Register to comment.