1

Since file inputs are not allowd to be pre-populated, how do i tell craft that a required asset field is already filled in the front end edit form? Can’t seem to figure this one out.

Edit: Users can create entries from the front end. Those entries have at least one required field which is an asset (image). Creating an entry works fine. However, when editing an entry the user should be able to change the asset as well so we give them the file input too when editing the entry. If they choose to leave that alone the entry couldn’t get saved since the file input stays empty but is still required.

  • Can you post more detail? Not really clear what you’re trying to do here. – Brandon Kelly Oct 22 '14 at 17:56
  • 1
    Users can create entries from the front end. Those entries have at least one required field which is an asset (image). Creating an entry works fine. However, when editing an entry the user should be able to change the cover as well so we give them the file input too when editing the entry. If they choose to leave that alone the entry couldn’t get saved since the file input stays empty but is still required. Solved it for now by making the file input hidden first and only changing its type attribute to file (using jquery) once the cover get’s deleted, ajax-style. Makes sense? – Marcus Scheller Oct 22 '14 at 21:39
  • 1
    Yes the JavaScript solution is going to be your best bet here. You should post that as an official answer to the question ;) – Brandon Kelly Oct 22 '14 at 21:42
  • Cool. Will do :) – Marcus Scheller Oct 22 '14 at 21:44
0

Solved it for now by making the file input hidden first and only changing its type attribute to file (using jquery) once the asset get’s deleted, ajax-style.

  • I have a similar set up. Users can publish entries that contain an asset field which is set to "required". They should also be able to edit these entries. In my edit form, I have a hidden field for the asset: <input type="hidden" name="fields[imageFile]" value=""> I'm not sure what, if anything, to put as the value. The form is not saving because required field not filled in. Is JavaScript (jQuery, other) the only way? If so, would you be willing to share your solution in more detail? Is there another, non JS, solution? – Andrea DeMers May 25 '17 at 20:04
  • It looks like I got it working with hidden field as follows: <input type="hidden" name="fields[imageFile][]" value="{{ image.id }}"> – Andrea DeMers May 25 '17 at 21:22
  • Hi Andrea. It was national holiday here in Germany so I only now had time to look into it. You got it working? – Marcus Scheller May 29 '17 at 7:32
  • Hi Marcus, after some time away from this project, I've come back to it to discover that my solution above does not work after all. Would it still be possible to share your JS solution? Thanks! – Andrea DeMers Dec 20 '17 at 19:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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