The Trav <[email protected]> writes:
> Hi All,
>
> I've been chasing this one for a while and found a few posts dancing
> around the edge, but so far I haven't seen any solid answer on it.
>
> Most MappedTypeField's have auto generated form fields, including
> Select elements if you override the correct method.
>
> I was hoping MappedDateTime would have an auto generated field that
> included a JQuery DatePicker, given that if it's a required field, you
> need it to do your crud editing.
>
>
> Is there anything at all like that in the framework? Or do I have to
> figure out how to implement it myself?
You can use this as a starting point:
class FancyMappedDate[T<:Mapper[T]](fieldOwner: T) extends
MappedDate[T](fieldOwner) {
override def fieldId = Some(Text(name))
override def setFromAny(f : Any): Date = f match {
case v :: vs =>
tryo({java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM,
S.locale).parse(v.toString)}).map(d => this.set(d)).openOr(this.is)
case d:Date => this.set(d)
case _ => super.setFromAny(f)
}
override def _toForm: Box[NodeSeq] = {
val onLoad ="""jQuery(function($){
$.datepicker.setDefaults($.datepicker.regional.da)
$('#"""+name+"""').datepicker({showOn: 'both', buttonImage:
'/images/calendar.gif', buttonImageOnly: true});
});
"""
S.fmapFunc({s: List[String] => this.setFromAny(s)}){funcName =>
Full(<xml:group>
<head>
<script type="text/javascript"
src="/scripts/jquery/jquery-ui-1.7.2.custom.min.js"></script>
<script src="/scripts/jquery/i18n/jquery-ui-i18n.js"
type="text/javascript"></script>
<link type="text/css"
href="/css/south-street/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" charset="utf-8">{onLoad}</script>
</head>
<input type='text' id={fieldId}
name={funcName}
class="date-pick dp-applied"
value={is match {case null => "" case d =>
""+java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM,
S.locale).format(d)}}/>
</xml:group>)
}
}
}
--
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.