Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    DateTime picker. Today button change to Now and give current date and time

    As title says, would love to have my datetime fields to have the regular Date picker with the ability to give the current date and time when choosing the Today button, which I would retitle as Now.

    I'm not sure how to do this.

    #2
    I'm using the latest:

    SNAPSHOT_v8.3d_2012-09-21/PowerEdition Deployment 2012-09-21
    GWT-2.4
    Eclipse Indigo

    I'm trying to extend DateChooser so that when the todayButton is clicked, I will set the value to the current Date/Time. However, I'm not sure how to detect when the todayClick event has occured. According to the docs from:

    http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/widgets/DateChooser.html#todayClick()

    The todayClick method should be fired. I cannot get that to work. Perhaps I should look at the event object passed into onChangedData? Does the event object have info concerning the todayClick occuring? Here's my code:

    Code:
    	public void onModuleLoad() {
    		final DynamicForm form = new DynamicForm();
    		form.setAutoFocus(true);
    		form.setWidth(200);
    
    		MYDateTimeItem now = new MYDateTimeItem();
    		now.setTitle("Now");
    		form.setFields(now);
    
    		form.draw();
    	}
    	
    	public class MYDateTimeItem extends DateTimeItem {
    		private DateChooser DC;
    		private MYDateTimeItem myself;
    		
    		public MYDateTimeItem() {
    			myself = this;
    			
    			DC = new DateChooser() {
    [B]
    				@Override
    				public void todayClick() {
    					SC.say("todayClicked!");
    				}
    				@Override
    				public void cancelClick() {
    					SC.say("cancelClicked!");
    				}
    [/B]
    			};
    			DC.addDataChangedHandler(new DataChangedHandler(){
    				@Override
    				public void onDataChanged(
    						com.smartgwt.client.widgets.events.DataChangedEvent event) {
    					DC.hide();
    					
    					Date date= new Date();
    					DC.setData(date);
    					myself.setValue(date);
    				}
    			});
    			DC.setShowCancelButton(true);
    			DC.setCancelButtonTitle("Cancel");
    			DC.setTodayButtonTitle("Now");
    			
    	        PickerIcon datePicker = new PickerIcon(PickerIcon.DATE, new FormItemClickHandler() {  
    
    				@Override
    				public void onFormItemClick(FormItemIconClickEvent event) {
    					DC.show();
    				}  
    	        });  
    
    	        this.setShowPickerIcon(false);
    			setIcons(datePicker);
    			
    		}

    Comment

    Working...
    X