Announcement

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

    FileItem and UploadItem don't fire changedHandler

    I have a problem with FileItem and UploadItem:

    in order to enable an (upload) button, I need to know, when the user has selected a file.
    I added a changed handler to my items, but it never fires.

    Following is some test code, which illustrates this:
    Code:
    package org.yournamehere.client;
    
    import com.google.gwt.core.client.EntryPoint;
    
    import com.smartgwt.client.widgets.form.DynamicForm;
    import com.smartgwt.client.widgets.form.fields.ButtonItem;
    import com.smartgwt.client.widgets.form.fields.FileItem;
    import com.smartgwt.client.widgets.form.fields.SubmitItem;
    import com.smartgwt.client.widgets.form.fields.UploadItem;
    import com.smartgwt.client.widgets.form.fields.events.ChangedEvent;
    import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
    import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
    import com.smartgwt.client.widgets.form.fields.events.ClickHandler;
    
    public class MainEntryPoint implements EntryPoint {
        private DynamicForm form = new DynamicForm();
        private FileItem fileName = new FileItem("fi", "Select");
        private SubmitItem doit = new SubmitItem("upload", "Upload");
        private ButtonItem save = new ButtonItem("save", "Save");
    
        public void onModuleLoad() {
            doit.setDisabled(true);
            save.setDisabled(true);
            fileName.addChangedHandler(new ChangedHandler() {
                @Override
                public void onChanged(ChangedEvent event) {
                    System.err.println("FI Changed");
                    save.setDisabled(false);
                }
            });
            UploadItem uli = new UploadItem("UploadItem", "Select file");
            uli.addChangedHandler(new ChangedHandler() {
                @Override
                public void onChanged(ChangedEvent event) {
                    System.err.println("ULI Changed");
                    doit.setDisabled(false);
                }
            });
            save.addClickHandler(new ClickHandler() {
               @Override
               public void onClick(ClickEvent event) {
                   System.err.println(fileName.getDataPath()+" "+fileName.getValue());
                   form.saveData();
               }
            });
    
            form.setCanSubmit(true);
            form.setAction("/upload");
            form.setItems(uli, doit, fileName, save);
            form.draw();
        }
    }
    Is there any other flag that I need to set on the form or field for the handler to fire?

    I'm using GWT 2.0.4 and SmartGWT 2.3

    #2
    Please, anybody out there can help me with this?!?!?!

    Isomorphic, are you still there?

    Comment


      #3
      AFAIK, this event is browser dependent, and unreliable. You can do this instead:

      Map<String, String> errors = new HashMap<String, String>();
      if (uploadItem.getValueAsString() != null) {
      // submit form
      } else {
      errors.put("uploadfile", "No file selected");
      }
      this.setErrors(errors, true);


      Displays the (!) next to the input field.

      regards,
      Andrius

      Comment

      Working...
      X