Announcement

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

    Want to use filter for file open window

    In our application we are using a DataSource to populate a browse button for selecting a file to open. If we click on that browse button it will open a file open window to select the desire file. Now I want to apply a filter for file extension in that window. Please suggest the solution. I need to filter out two to three type of file e.g. “.Zip”,”. Jpeg” etc.

    At present that file open window actually applies the default filter which will show the entire available file in the present directory.
    The DataSource field is given below:

    <field name="Uploadfile" required="false" type="binary" title="Upload File" />

    We are using GWT 2.3.0(using gwt-servelet.jar,gwt-dev.jar), Smart GWT 4.0 (smartgwt.jar, smartgwtpro.jar),Internet explorer 11/IE8/IE9.

    #2
    See the doc for FileItem/UploadItem.accept

    Comment


      #3
      Thanks for the reply. But in my case I got FormItem instead of UploadItem/ FileItem .as it is known that FormItem is the super class of super class for UploadItem/ FileItem, setAccept() method could not be use in this case. is there any similar type of solution which can I use for FormItem.

      The DataSource field is given below:

      <field name="Uploadfile" required="false" type="binary" title="Upload File" />

      Java file code is:
      DynamicForm fileChoose = new DynamicForm();

      DataSource dataSource = DataSource.get(DataSource Name);


      fileChoose.setDataSource(dataSource);

      fileChoose.getField("Uploadfile").setWidth(300);
      fileChoose.getField("Uploadfile").setWrapTitle(false);
      fileChoose.getField("Uploadfile").setTitle("Select local files");


      now fileChoose.getField("Uploadfile") actually return FormItem.

      Comment


        #4
        This should do it:

        Code:
                UploadItem editor = new UploadItem();
                editor.setAccept("*.jpg;");
                dsField.setEditorProperties(editor);

        Comment


          #5
          Actually, we spoke in error there - we'lll take a look and get back to you

          Comment


            #6
            In your case, just supply field properties to the form when you create it.

            Code:
            DataSource dataSource = DataSource.get(DataSource Name);
            
            DynamicForm fileChoose = new DynamicForm();
            fileChoose.setDataSource(dataSource);
            fileChoose.setUseAllDataSourceFields(true);
            
            UploadItem editor = new UploadItem("Uploadfile");
            editor.setAccept("image/*");
            fileChoose.setFields(editor);

            Comment


              #7
              We implement the solution as you suggested in your last reply but still we didn’t get the expected file filtering output. We are trying to filter out “*.zip” and “*.jpg” files but actually all the time in file open window as default option we are getting “ALL FILES (*.*)” .

              Also we are redesigning it with FileItem / UploadItem instead of FormItem but still no expected O/P we are getting.

              Code with FileItem:

              FileItem uploadFile = new FileItem("Uploadfile ");
              uploadFile .setWidth(450);
              uploadFile .setWrapTitle(false);
              uploadFile .setTitle("Select local files");
              uploadFile .setAccept("*.Zip");

              Comment


                #8
                Firstly, "*.zip" would not be expected to work in all browsers - it should either be a MIME type, like "application/zip" or it should not have the * prefix - like ".jpg".

                Secondly, the file open dialog is a browser-specific entity. We provide the "accept" filter options to it, but what actually happens is native to the browser. In some cases, your custom option will be selected by default, but the "All Files" option will remain - in others, the custom option is available, but "All Files" is selected by default.

                Note also that a file upload dialog at the client should not be used as a data validation method - that is, if file-type is limited then proper validation should be performed at the server.
                Last edited by Isomorphic; 29 Jul 2015, 04:31.

                Comment


                  #9
                  Hi Isomorphic,

                  could you update the docs of UploadItem.setAccept() with the information that ".jpg" and especially "image/*" are supported? (your posts #6 and #8).
                  Currently it says:
                  A comma-separated list of valid MIME types, used as a filter for the file picker window.
                  I think this is a valuable setting and not having to list all image MIME-types is a very good thing.

                  Best regards
                  Blama

                  Comment

                  Working...
                  X