Announcement

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

    DateItem.setUseTextField(true)

    Hi Isomorphic,

    please take a look at this test case.

    Click image for larger version

Name:	DateItem bug.gif
Views:	165
Size:	24.6 KB
ID:	260016

    Code:
    package com.smartgwt.sample.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.smartgwt.client.core.KeyIdentifier;
    import com.smartgwt.client.util.Page;
    import com.smartgwt.client.util.PageKeyHandler;
    import com.smartgwt.client.util.SC;
    import com.smartgwt.client.widgets.IButton;
    import com.smartgwt.client.widgets.Window;
    import com.smartgwt.client.widgets.events.ClickEvent;
    import com.smartgwt.client.widgets.events.ClickHandler;
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.DateItem;
    import com.smartgwt.client.widgets.form.fields.FormItemIcon;
    import com.smartgwt.client.widgets.form.fields.TextItem;
    import com.smartgwt.client.widgets.form.fields.events.FormItemClickHandler;
    import com.smartgwt.client.widgets.form.fields.events.FormItemIconClickEvent;
    import com.smartgwt.client.widgets.form.fields.events.PickerIconClickEvent;
    import com.smartgwt.client.widgets.form.fields.events.PickerIconClickHandler;
    import com.smartgwt.client.widgets.layout.VLayout;
    
    public class BuiltInDS extends VLayout implements EntryPoint {
        private IButton recreateBtn;
    
        public void onModuleLoad() {
            KeyIdentifier debugKey = new KeyIdentifier();
            debugKey.setCtrlKey(true);
            debugKey.setKeyName("D");
    
            Page.registerKey(debugKey, new PageKeyHandler() {
                public void execute(String keyName) {
                    SC.showConsole();
                }
            });
    
            setWidth100();
            setHeight100();
    
            recreateBtn = new IButton("Recreate");
            recreateBtn.addClickHandler(new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                    new MyWindow().show();
                }
            });
            addMember(recreateBtn);
            new MyWindow().show();
            draw();
        }
    
        private class MyWindow extends Window {
            public MyWindow() {
                setWidth(600);
                setHeight(300);
                setMembersMargin(0);
                setModalMaskOpacity(70);
                setShowMinimizeButton(false);
                setIsModal(true);
                setShowModalMask(true);
                centerInPage();
    
                DateItem dateItemBirthday = new DateItemBirthday("Test");
                dateItemBirthday.setUseTextField(true);
    
                DynamicForm df = new DynamicForm();
                df.setFields(dateItemBirthday);
                addItem(df);
            }
        }
    
        private class DateItemBirthday extends DateItem {
            public DateItemBirthday(String name) {
                super(name);
                setWidth(225);
                // when text field then not editable
                setTextFieldProperties(new TextItem() {
                    {
                        setCanEdit(false);
                    }
                });
    
                // Delete date icon
                FormItemIcon icon = new FormItemIcon();
                icon.setSrc("http://127.0.0.1:8888/builtinds/sc/skins/Enterprise/images/DynamicForm/search_icon.svg");
                icon.addFormItemClickHandler(new FormItemClickHandler() {
                    @Override
                    public void onFormItemClick(FormItemIconClickEvent event) {
                        if (!getUseTextField())
                            setUseTextField(true);
                        setValue((Object) null);
                    }
                });
                setIcons(icon);
    
                // Add button to edit birthday
                addPickerIconClickHandler(new PickerIconClickHandler() {
                    @Override
                    public void onPickerIconClick(PickerIconClickEvent event) {
                        if (getUseTextField()) {
                            setUseTextField(false);
                            setValue(getValue());
                        }
                    }
                });
            }
        }
    }
    This was working fine using v12.0p_2019-03-23/PowerEdition Deployment (built 2019-03-23) and it's not working using current built.

    Best regards
    Pavo

    #2
    Can you clarify what behaviour you're trying to achieve here? It looks like you're trying to show a text-item when the field is not editable, and show the separate date-part selectors when you go into edit mode. Is that right?

    If so, that's exactly what setAutoUseTextField(true) (the default) does automatically, and your direct manipulation of useTextField (not canEdit) at runtime is interfering with it...

    You can restore whatever previous manual behavior you had with a call to setAutoUseTextField(false) - or you can instead get rid of your manipulation of useTextField and call setCanEdit(true) to show the live pickers and setCanEdit(false) to show the (non-editable) textField. Value-retention is also automatic across those calls, so no need for setValue() calls.

    Comment


      #3
      Hi Isomorphic,

      your assumption is correct. This is actually old code that I didn't write but I'm testing our app with the new smartGWT version so I noticed this behavior.
      Thanks to your detailed explanation, I fixed this problem easily. Thank you very much!

      Best regards
      Pavo

      Comment

      Working...
      X