How to get DateTime input on Play! CRUD form?

By default, the java.util.Date field is represented in the CRUD form as a simple "DATE" input.

 public class DatedModel extends Model { public Date creationDate; 

in the CRUD admin, I see:

 creationDate [TEXTINPUT] yyyy-MM-dd format. 

Is there a way, instead of entering DateTime, only in the selected fields (not all of them change application.conf date.format )?

Is there any way to influence which β€œwidget” is used for a given field in the β€œautomatic” CRUD administrator?

+4
source share
2 answers

Finally, I found my answer in the documentation:

You can really customize each field ; a more detailed example can be found on the lunatech blog using jquery datatables , which also shows how to change pagination.

 #{crud.table fields:['name', 'company']} #{crud.custom 'company'} <a href="@{Companies.show(object.company.id)}"> ${object.company.name} </a> #{/crud.custom} #{/crud.table} 

PS.

The @AditSaxena hint was a good and really easy solution; but not what I wanted because it is unacceptable that the "hint" is incorrect! Absolutely confusing for the user!

So, to enter the date and time (specific question), we can combine the annotation (described in the doc )

  @As(lang={"*"}, value={"yyyy-MM-dd hh:mm:ss"}) 

with a user prompt, for example.

  #{crud.custom 'mydate'} <span class="crudHelp"> Date format: etcetc. </span> ... #{/crud.custom} 

I will also point out that you can write your own validator

Other helpful questions:

+2
source

Something like this in your application.conf application:

 module.crud=${play.path}/modules/crud date.format=yyyy-MM-dd hh:mm:ss 

Then in the model:

 package models; import java.util.*; import play.data.binding.As; import play.db.jpa.*; import play.data.validation.*; import play.templates.*; import play.mvc.Scope.*; import javax.persistence.*; import play.Logger; import play.templates.JavaExtensions; @Entity public class Product extends Model { @As(lang={"*"}, value={"yyyy-MM-dd hh:mm:ss"}) public Date creationDate; } 

Your controller:

 package controllers; import play.*; import play.mvc.*; import java.util.*; import models.*; public class Products extends CRUD { } 
+3
source

Source: https://habr.com/ru/post/1387031/


All Articles