Grails field pattern for different time formats

隐身守侯 提交于 2019-12-25 02:38:38

问题


I'm trying to use patterns for my gsp file in Grails. I want to check if the time entered is in the correct format. For example: 12.15 == 12:15 == 12,15 == 12-15 and so on.

<g:field type="text" name="startTime" class="date" pattern="\\$##:##"/>
<g:field type="text" name="endTime" class="date" pattern="[0-9]{2}:[0-9]{2}" />

That's my code. The patterns are just some trys. Maybe someone knows a solution.

Greetings Nik


回答1:


the pattern in your g:field tag will be pass into date template (for example: /_fields/date/_field.gsp) like you pass parameters into other templates. You can access it by ${pattern}.

You can use any validator such as bootstrap_validator or jquery_inputmask to do the task




回答2:


I found a solution:

<g:textField name="startTime" class="date"
        value="${formatDate(format:'HH:mm',date:record.start)}" pattern="\\d{1,2}(:\\d{0,2})?" />
<g:textField name="endTime" class="date"
        value="${formatDate(format:'HH:mm',date:record.end)}" pattern="\\d{1,2}(:\\d{0,2})?"/>

I just skiped the part with different dots. Now it shows a warning if you use the wrong pattern.



来源:https://stackoverflow.com/questions/25525375/grails-field-pattern-for-different-time-formats

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!