2

Can you guys help me with my little problem? this is my select tag:

<%= f.select :department_id, options_for_select(Department.in_order.map {|d| [d.name, d.id]}, obj.department_id), { prompt: true }, class: 'form-control input-sm', disabled: lambda {action_name == 'revise'} %>

if disabled: true is set, I get "Department is invalid" error on my validation. When not set, everything is fine.

Charlie
  • 341
  • 3
  • 11

1 Answers1

2

This is due to the fact that HTML fields when disabled are not submitted with the form. What you need is readonly. Readonly gives you the same functionality as disabled but is still submitted with the form.

http://www.w3schools.com/tags/att_input_readonly.asp

ericsaupe
  • 162
  • 3
  • 12
  • Thanks for the info and I will mark that as an answer. BTW, I read the documentation in apidock, and readonly attribute is not available for select tag. Even in raw html there's no readonly attribute. Perhaps, I should change my form's flow. – Charlie Aug 18 '14 at 16:17
  • 1
    Here's another StackOverflow question that may help with that problem, http://stackoverflow.com/q/368813/575985. They suggest keeping the select disabled but having a hidden input with the same name and value so that it will be passed with the form. – ericsaupe Aug 18 '14 at 16:24
  • :D Thanks a lot! I will try re-enabling select tag on submit. – Charlie Aug 18 '14 at 16:52