Ask A Question


You’re not receiving notifications from this thread.

Flatpickr with "Present" value as well.

Gerard Donnelly asked in General

I am currently adding date ranges for jobs in my app. I want the user to pick the start and end dates using flatpickr gem. I also want the user to be able to set the field to "Present" if they are still working there. I was wondering what the best way to implement this would be.
See the screenshots from how LinkedIn do it.


Thanks for your help guys.


Hey Gerard,

I would probably use Javascript to do two things when checked:

  1. Hide/show the end date field
  2. Clear the value for the date fields

Flatpickr write the selected value to a form field, so it can be submitted to the server. That's the field you'll want to clear out in the JS.

Then just make sure your end date field is marked as optional in your database so it can be null.


Thanks for your explanation Chris.
To confirm.

Have 3 fields:
Start Date - Date Field
End Date - Date Field
Currently Working - Boolean

If Currenly Working (Boolean) is true; hide End Date field and clear any value from it.




Yep, and I don't know that you necessarily need the currently working boolean in the database. You can just add some methods in your model to delegate to the end_date column.

class Job
  def currently_working?

Then you can just use that method to set the checked attribute on the checkbox by default when editing.


Thats a great help Chris.


Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,038+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.