This Question is Assumed Answered

1 "correct" answer available (5 pts) 13 "helpful" answers available (3 pts)
5 Replies Last post: Jul 7, 2008 7:09 PM by Poseidon.UD

DateField's Readonly

Jul 7, 2008 1:59 AM

Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008

heros,Help me

use Curl's DateField,if i want the DateField is Readonly, How can i do?

{on ValueChanged do

set oldvalue to the controler? || bogus sourcecode

}

Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
1. Re: DateField's Readonly Jul 7, 2008 2:55 AM
This is a sample using your idea, but I don't know whether this is a best solution:
 {define-class public MyDateField {inherits DateField}
  {field public _origin-value:#DateTime}
  {constructor public {default ...}
    {construct-super {splice ...}
    }
    {set self._origin-value = self.value}
    {self.add-event-handler
        {on ValueChanged at df:DateField do
            {set self.value = self._origin-value}
        }
    }
    {self.add-event-handler
        {on kp:KeyPress at df:DateField do
            {if kp.normal? or
                kp.value == KeyPressValue.delete or
                kp.value == KeyPressValue.backspace then
                
                {kp.consume}
            }
        }
    }
  }
 
}
 
{MyDateField value = {DateTime}}
Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
2. Re: DateField's Readonly Jul 7, 2008 3:03 AM
in response to: tdeng
Maybe you also need to disable
  input-method-enabled?
Click to view tdeng's profile Level 3 tdeng 35 posts since
Oct 17, 2007
3. Re: DateField's Readonly Jul 7, 2008 3:08 AM
I think I find a simpler way to do this:

{DateField value = {DateTime},max-value={DateTime}, min-value={DateTime}}


If you limit the max-value, min-value to the same date as value, then this DateField will keep unchangable, ie, "readonly".
Click to view Kamal's profile Curl 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
    }
}
 
Click to view Poseidon.UD's profile Level 2 Poseidon.UD 37 posts since
Jul 3, 2008
5. Re: DateField's Readonly Jul 7, 2008 7:09 PM
in response to: Kamal

so many ways to do it,thank u very much.