2

How do you use Rails date_select form helper and generate a seperate ng-model for month and for year?

// Slim

= f.date_select :from, { order: [:month, :year], start_year: Time.now.year, end_year: 1990, include_blank: true }, { :'ng-required' => 'isRequired' }

The date_select makes it easy to set differenct prompts per each field. Is there any way to do this with your custom attributes?

date_select("article", "written_on", prompt: { day: 'Select day', month: 'Select month', year: 'Select year' })

1 Answer 1

0

The problem is that date_select creates 3 select_tag fields(one for month, year, and day). You can add the ng-model tag within html_options for date_select, but the problem is that all 3 select fields will have an identical ng-model tag with the same name. Angular doesn't like having multiple ng-model objects with the same name, and I don't know how to get around this. The solution I used was just to recreate what date_select does and create 3 select_tag fields. It's definitely not as elegant as the date_select field but it does work. I'd love to hear if anyone has a better solution!

Your Answer

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

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