[CLOSED] File Upload Field example

  1. #1

    [CLOSED] File Upload Field example

    Hi Guys,

    I have a couple of question related to the mvc example located at http://mvc.ext.net/#/Form_FileUploadField/Basic/, the form panel section.

    I would like to implement a window with some fields and a fileUpload, the code is below:

        @(Html.X().Window()
        .ID("MediaAddWindow")
        .Width(windowWidth)
        .Icon(Icon.UserAdd)
        .Title("Nuovo contenuto multimediale")
        .Resizable(false)
        .Closable(false)
        .Border(true)
        .Layout(LayoutType.Fit)
        .CloseAction(CloseAction.Destroy)
        .Modal(true)
        .Items(
            Html.X().FormPanel()
                .ID("MediaAddFormPanel")
                .MarginSpec("0 0 0 0")
                .Frame(true)
                .Layout(LayoutType.VBox)
                .BodyPadding(5)
                .Defaults(d =>
                {
                    d.Add(new Parameter("anchor", "95%", ParameterMode.Value));
                    d.Add(new Parameter("msgTarget", "side", ParameterMode.Value));
                })            
                .FieldDefaults(def =>
                {
                    def.MsgTarget = MessageTarget.Side;
                })
                .Items(
                    field =>
                    {
                        field.Add(
                            Html.X().ComboBoxFor(m => m.strSelectedMediaType)
                            .Items(Model.listMultimediaType)
                            .FieldLabel("Tipologia")
                            .Editable(false)
                            .Width(componentWidth)
                            .LabelWidth(labelWidth));
    
                        field.Add(
                            Html.X().TextFieldFor(m => m.strName)
                                .FieldLabel("Nome")
                                .Width(componentWidth)
                                .LabelWidth(labelWidth)
                                .AllowBlank(false));
    
                        field.Add(
                            Html.X().TextAreaFor(m => m.strDescription)
                                .FieldLabel("Descrizione")
                                .Width(componentWidth)
                                .LabelWidth(labelWidth)
                                .AllowBlank(true));
    
                        field.Add(
                            Html.X().TextFieldFor(m => m.strAlt)
                                .FieldLabel("Testo alternativo")
                                .Width(componentWidth)
                                .LabelWidth(labelWidth)
                                .AllowBlank(true));
    
                        field.Add(
                            Html.X().FileUploadField()
                                .ID("UploadFileMediaID")
                                .EmptyText("Selezionare un contenuto")
                                .FieldLabel("Media")
                                .ButtonText("")
                                .Width(componentWidth)
                                .LabelWidth(labelWidth)
                                .Icon(Icon.ImageAdd));
    
                    }
                )
            .Buttons(
                Html.X().Button().Text("Invia")
                            .DirectEvents(de =>
                            {
                                de.Click.Url = Url.Action("UploadClick", "Admin");
                                de.Click.IsUpload = true;
                                de.Click.FormID = "MediaAddFormPanel";
                                de.Click.Before = @"if (!#{MediaAddFormPanel}.getForm().isValid()) { return false; }
                                Ext.Msg.wait('Trasferimento in corso...', 'Trasferimento');";
                                de.Click.Failure = @"Ext.Msg.show({
                                    title   : 'Errore',
                                    msg     : 'Errore durante il trasferimento',
                                    minWidth: 200,
                                    modal   : true,
                                    icon    : Ext.Msg.ERROR,
                                    buttons : Ext.Msg.OK
                                });";
                            }),
                            
                Html.X().Button().Text("Chiudi").Handler("window.Hsi.adminModule().CloseAddWindow();")
            )
        )
        )
    In yours example the formpanel is wrapped with:
    <form id="fileUpload" enctype="multipart/form-data">
    Should I Set the enctype parameter? How can I do in my code?

    Thanks

    Best regards.

    Andrea

    Edit:

    I was wondering if exist a "best practice" for managing file limit exceding size; editing the above code in this way:
    de.Click.Failure = "failureManagement(response, result, type, action, extraParams)";
    I have done some debug, in the result object I have the complete stack trace with error detail but is there a property or something else that tells the error is related to file size?

    Thanks
    Last edited by Daniil; Aug 20, 2014 at 11:56 AM. Reason: [CLOSED]
  2. #2
    Hi @aguidali,

    Should I Set the enctype parameter?
    I think it is not required in your case.

    I was wondering if exist a "best practice" for managing file limit exceding size
    Please start a new forum thread.
  3. #3
    Hi Daniil,

    I have small knowledge about this but the enctype= multipart/form-data parameter should be used on a form when there is an upload file input.

    Why do you think it is not required?

    However the example seems to work correctly without the parameter (tested only on dev pc, I hope that it works also in production).

    Thanks
  4. #4
    I have small knowledge about this but the enctype= multipart/form-data parameter should be used on a form when there is an upload file input.
    Yes, you are right. But there is no <form> in your test case as well, right?:) A <form> HTML element and a FormPanel component are not the same. Moveover, a FormPanel is not rendered as a <form> element. But it can create a <form> element if needed. For example, a <form> is created automatically in your code, because of this setting:
    de.Click.FormID = "MediaAddFormPanel";
    Also it detects if the enctype attribute is required or not and adds it if needed.
  5. #5
    Thanks Daniil,

    You can close the thread.

    Best regards.

    Andrea

Similar Threads

  1. File Upload Field In Gridpanel
    By kavitha in forum 2.x Help
    Replies: 3
    Last Post: Sep 30, 2013, 3:24 PM
  2. File Upload Field Browse not Open ?
    By nazmulrockon in forum 2.x Help
    Replies: 9
    Last Post: Jun 21, 2012, 9:01 AM
  3. [CLOSED] Clone Upload File Field
    By imaa in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 17, 2011, 2:29 AM
  4. File Upload Field Problem
    By OSSAGHO in forum 1.x Help
    Replies: 0
    Last Post: Sep 19, 2011, 1:09 PM
  5. [CLOSED] File Upload Field
    By SymSure in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Mar 30, 2010, 7:24 PM

Tags for this Thread

Posting Permissions