timePicker in same style as datePicker or a flag telling datePicker to also have hour/minutes.

Submitted by Terje Pedersen on 26 April 2011 at 08:43

On 3 May 2011 at 09:59 Terje Pedersen commented:

Here is my version modified from the datePicker with onchange:

import mobl
import mobl::ui::generic

style narrowNumFieldStyle {
-webkit-appearance: none;
-webkit-box-flex: 100;
-webkit-rtl-ordering: logical;
-webkit-user-select: text;
-webkit-text-size-adjust: 140%;
-moz-text-size-adjust: 140%;
-webkit-appearance: textarea;
background: #fff -webkit-gradient(linear, 0% 0%, 0% 100%, from(white),
to(white) );
border: 0;
font-size: 1em;
height: 1em;
padding: 0;
text-align: center;
width: 3em;
}

control narrowNumField(n : Num, onchange : Callback = null) {
<input type=“text” databind=n onkeyup={
if(!Math.isNaN(n)) {
onchange(null);
}
} class=narrowNumFieldStyle/>
}

control timePicker(d : DateTime, onchange : Callback = null) {
script {
if(d==null) { d=now(); }
}

var visible = false
var hours = d.getHours()
var minutes = d.getMinutes()

label((hours.toString().length==1?“0”:““)+hours.toString()+”:”+(minutes.toString().length==1?“0”:““)+minutes.toString(), onclick={
visible = visible ? false : true;
})


when(visible) {

button(”+”, onclick={
d.setHours(d.getHours() + 1);
hours = d.getHours();
d = d;
onchange(d);
})

narrowNumField(hours, onchange={ d.setHours(hours); d=d; onchange(d); })

button(“-”, onclick={
d.setHours(d.getHours() - 1);
hours = d.getHours();
d = d;
onchange(d);
})


button(“+”, onclick={
d.setMinutes(d.getMinutes() + 1);
minutes = d.getMinutes();
d = d;
onchange(d);
})

narrowNumField(minutes, onchange={ d.setMinutes(minutes); d=d; onchange(d);})

button(“-”, onclick={
d.setMinutes(d.getMinutes() - 1);
minutes = d.getMinutes();
d = d;
onchange(d);
})

}

}

On 11 May 2011 at 16:28 Zef Hemel commented:

Excellent. I’ll add a slightly modified version of this to mobl::ui::generic::datepicker ok?


On 11 May 2011 at 18:00 Terje Pedersen commented:

Thats ok. I updated it to the latest version earlier today.


On 1 June 2011 at 11:32 Zef Hemel tagged 0.4.4

On 1 June 2011 at 11:32 Zef Hemel closed this issue.

On 14 July 2011 at 12:13 Terje Pedersen commented:

Haven’t looked at your modifed version but both mine and the mobl included one doesn’t update when changing the DateTime parameter variable from code. It works with the datePicker.


On 14 July 2011 at 12:37 Terje Pedersen commented:

Moved the toTimeString string concat to a function and used that instead for the label, and it worked :) But it should have been added DateTime.toTimeString


function toTimeString(d : DateTime) : String {
var hours = d.getHours();
var minutes = d.getMinutes();

return (hours.toString().length==1?"0":"")+hours.toString()+":"+(minutes.toString().length==1?"0":"")+minutes.toString();

}

Log in to post comments