Kamal 139 posts since
Oct 17, 2007
4.
Re: DateField's Readonly Jul 7, 2008 6:26 AM
There are different ways to make the DateField read only. The simplest will be to set the enabled? property to false. Otherwise you use the suggestions given by others or just use the CustomDateField that I hacked up quickly.
Do not use the DateField data model to change the value.
{curl 6.0 applet}
{curl-file-attributes character-encoding = "windows-latin-1"}
{define-class public CustomDateField {inherits DateField}
{constructor public {default
ui-object:#DateFieldUI = null,
min-value:#DateTime = null,
max-value:#DateTime = null,
value:#DateTime = null,
prompt:#String = null,
locale:#Locale = null,
calendar-control:CalendarControl = {CalendarControl takes-focus? = false},
...
}
{construct-super
ui-object = ui-object,
min-value = min-value,
max-value = max-value,
value = value,
prompt = prompt,
locale = locale,
calendar-control = calendar-control,
...
}
}
{setter public {value val:#DateTime}:void
{if self.editable? then
set super.value = val
}
}
{method public {set-value-with-events val:#DateTime}:void
{if self.editable? then
{super.set-value-with-events val}
}
}
{local-option public editable?:bool = true
{if-non-null ui-object = self._ui-object then
{self.make-editable ui-object asa Box, editable?}
}
}
{setter public {ui-object ui:ControlUI}:void
set super.ui-object = ui
{self.make-editable ui asa Box, self.editable?}
}
{method private {make-editable box:Box, editable?:bool}:void
set self.calendar-control.enabled? = editable?
{CustomDateField.make-editable-aux box, editable?}
}
{define-proc private {make-editable-aux box:Box, editable?:bool}:void
{type-switch box
case sc:SpinControl do
set sc.editable? = editable?
else
{for c in box.graphical-children do
{type-switch c
case box:Box do
{CustomDateField.make-editable-aux box, editable?}
}
}
}
}
}
{def df = {CustomDateField}}
{value df}
{CheckButton
label = "editable?",
value = df.editable?,
{on e:ValueChanged at cb:CheckButton do
set df.editable? = cb.value
}
}