Simple_form: required option being ignored

Created on 6 Jan 2017  路  4Comments  路  Source: heartcombo/simple_form

I am trying to create a file input field that is required, but simple_form simply ignores/removes the option specified in the code. However, it works well for other types of fields.

So, for example this code:

f.input :video_file, as: :file, input_html: { required: true }

Produces the following:

<input class="file optional" type="file" name="video[video_file]" id="video_video_file">

Is there any actual reason for this specificity towards file or is this a bug?

Most helpful comment

@gdgp cool, feel free to post your findings here when you fix it!

All 4 comments

Can you please provide a sample application that reproduces the error?

Dumb question... Why name="video[video_file]" has square brackets? Sometimes it only takes to reformulate a naming syntax for things to work correctly... My 2 cents, hope it helps.

@nashby While I was putting a simple example together to show you, it worked well.

For clarification, I re-tested the two main ways I tried to get it working before I posted the issue, and now it worked (with the other one I had tried but didn't work either):

<%= f.input :file, as: :file, required: true %>

So I guess I might have had some other thing interfering with it. In any case, thank you for your availability.

@gdgp cool, feel free to post your findings here when you fix it!

Was this page helpful?
0 / 5 - 0 ratings