Setting id attribute on input field using Wicket MultiFileUploadField

Ashley

In my panel class I have the following code:

private Fragment fileUploadField(String id, UploadFeedbackPanel feedbackPanel, ComponentFeedbackPanel componentFeedbackPanel) {
    String uploadType = isJSEnabled ? "multiple" : "single";
    Fragment uploadFragment = new Fragment( "uploadContainer", uploadType, this );

    if (isJSEnabled) {
        multipleUpload = new MultiFileUploadField( id, new PropertyModel<Collection<FileUpload>>( this, "multiUploads" ), MAX_FILES );
        uploadFragment.add( multipleUpload = multipleUpload);
        multipleUpload.add( newOnChangeAjaxBehavior( feedbackPanel, componentFeedbackPanel ) );
    } else {
        uploadFragment.add( singleUpload = new FileUploadField( id ) );
        singleUpload.add( newOnChangeAjaxBehavior( feedbackPanel, componentFeedbackPanel ) );
    }
    return uploadFragment;
}

I want to add a label for this field but I'm unable to get the actual input fields ID. You can see this working for the single upload field because the input field itself is render without any surrounding elements. This however doesn't seem to be exposed when using MultiFileUploadField.

An alternative acceptable answer would be using FileUploadField and a collection of files with the multiple=true attribute. However I am unsure how to limit the number of files to be MAX_FILES only.

    <label wicket:for="file"><wicket:msg key="file">File:</wicket:msg></label>
    <div wicket:id="uploadContainer" class="col-right">[upload fragment shows here]</div>
    <wicket:fragment wicket:id="single">
        <input wicket:id="file" type="file"/>
    </wicket:fragment>
    <wicket:fragment wicket:id="multiple">
        <div wicket:id="file" class="mfuex"></div>
    </wicket:fragment>

Wicket version 6.15.0.

martin-g

MultiFileUploadField uses JavaScript to generate the input fields: https://github.com/apache/wicket/blob/master/wicket-core/src/main/java/org/apache/wicket/markup/html/form/upload/MultiFileUploadField.js#L91 See whether you can plug there somehow. If you find an elegant way we would be glad to include it in the next version of Wicket!

If you use 'multiple' attribute then check: How do I limit the number of file upload in html?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

setting the id attribute of an input element dynamically in IE: alternative for setAttribute method

How to target value of input field that has an id that is composed using Thymeleaf

Setting the id attribute with knockoutjs including a prefix

JQuery: setting focus on an input field on a specific page

Get (ONLY) Id of input field using .getAttribute

Getting the POST_ID of the Nearest input Field Using Jquery

selenium not setting input field value

Setting ID attribute of input field when using ActiveField in Yii2?

How to find value of input field using name attribute?

Why does putting an id attribute inside an input tag make the field required?

Setting value of all input fields with X ID using JS

Formatting and Setting Phone Number in input field in reactjs

Setting Focus on dynamically created input field without knowing its ID

accessing value of input field by id using jquery

Setting maxwidth on an input field in Bootstrap3

Setting title attribute for a disabled input

get Id of input field using JavaScript

Ejs input_field_tag method setting type attribute as 5

Match one of multiple specific values in input field using the pattern attribute

How in angular to set an input field focused using name, model or id?

jQuery setting input value attribute using .html() not working

Joomla - setting field attribute in a plugin

adding ID of input in the for attribute of label

Setting the opacity of a HTML input field's text

Create a label for each input of type text using input attribute (id, name)

How do I add 'list' attribute to an input field using jQuery?

Problem filling in an input field without an id or identifying attribute. (Puppeteer)

Show button if input text field is not empty in Wicket

How to use input field value attribute while using formControlName? [Angular]