PDA

View Full Version : [CLOSED] File Upload Field example



aguidali
Aug 19, 2014, 7:50 AM
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

Daniil
Aug 19, 2014, 2:10 PM
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.

aguidali
Aug 20, 2014, 10:01 AM
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

Daniil
Aug 20, 2014, 12:31 PM
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.

aguidali
Aug 20, 2014, 12:44 PM
Thanks Daniil,

You can close the thread.

Best regards.

Andrea