Add gem “bootstrap3-datetimepicker-rail” sử dụng datetime trong rails

Tram Ho

1. Introduction

Datepicker is a form of component that is familiar to you as a front-end, is a js library that supports creating datefields, daterange, widely used on many web applications. Its purpose is to display a calendar on a computer screen so that the user can easily select the date.

2. Implementation steps

Create project:

Add gem file:

add file app / assets / javascripts / application.js

Create another file: Touch app / assets / stylesheets / custom.scss and import:

Continue to add application.css file

create model:

later

Add the routes file:

Create file: Touch app / assets / javascripts / datetimepicker.js and add the following:

With the format: “dd / mm / YYYY”

Add the following content to the datetimepicker.js file

When custom with format: only time
Add the following content to the datetimepicker.js file

Custom with display field without icon

Change file datetimepicker.js

When Enabled / Disabled: to the default date: January 11, 2019, the current date: 12/20/2019 will be selected, the dates: 12/21/2019 and 12/22/2019 are disabled.

With the view mode displaying the year on the view, modify datetimepicker.js as follows:

Above are the steps to add gem “bootstrap3-datetimepicker-rail” to the rails application. The article has many shortcomings that are looking forward to everyone’s comments.

Share the news now

Source : Viblo