I have created a multiuploadField object in wicket project which allows to select files and submit the files after clicking on submit button. But I want to auto submit the form once the file are selected by the user and upload the file without clicking the submit button. Is it possible to do this? Is there any way of doing it using onChange event or anything else.
<form wicket:id="simpleUpload">
<fieldset>
<legend>Upload form</legend>
<p>
<div wicket:id="fileInput" class="mfuex" />
</p>
<input type="submit" value="Upload!" />
</fieldset>
</form>
Thanks in advance.
Yes, you have to use AjaxFormSubmitBehavior
with change
event for file input field.
As I can see, you use MultiFileUploadField
, so just add:
fileInput.add ( new AjaxFormSubmitBehavior(form/*optional*/, 'change')
{
@Override
protected void onSubmit ( AjaxRequestTarget target )
{
super.onSubmit ( target );
}
/* you can also override other methods here,
but note that Form's submit method will
be called too.*/
} );
Where fileInput
is file upload field, and form
is form where your field is stored. If there is no submit event occurs, then check onError
method if your form has some validations.
Note, that this behavior will be called each time you choose file from system file chooser. MultiFileUploadField
does not allow to select multiple files at the same time. Adds only one by one.
To select some files at once you can use FileUploadField
and HTML5 tag multiple
, so in your markup will be the following:
<input wicket:id="fileInput" type="file" multiple="multiple"/>
It will work only with HTML5, and for other version it will allows to load only one file, but submit approach, described above will work for this too.
UPDATE
Actually I have already describe most of this for you here. You should react somehow by accepting the answer or describing why this does not solve your problem.