Play! Framework and Uniformjs don't play nicely for file uploading
I am writing a small webapp in Play!, and trying to use UniformJS (http://uniformjs.com/) to make my form elements look good. One page of the app lets users upload a file:
#{ form @Application.upload(), id:'uploadform', enctype:'multipart/form-data'}
<input type="file" id="uploadFile" name="uploadFile"/>
<input type="submit" id="surveyChooseFileButton" class="button" value="Upload" />
#{/form}
The controller looks like this:
public static void upload(@Required File uploadFile, @Required String surveyName) {
...
}
This is all just like one of the Play! examples (http://www.playframework.org/documentation/1.0/5things#a5.Straightforwardfileuploadmanagementa), and that all works fine. The problem is when I apply Uniform to my file input:
$(function(){ $("input:file").uniform(); });
Now the controller receives a null File object! Is there any way around this?
UPDATE:
Removing the id's doesn't do it (although that seemed very plausible!). View-source on the o开发者_如何学Pythonffending element reveals:
<div id="uniform-uploadFile" class="uploader"> <!-- A new div -->
<!-- My input element turns invisible -->
<input id="uploadFile" type="file" name="uploadFile" size="19" style="opacity: 0;">
<!-- Uniform adds these -->
<span class="filename" style="-moz-user-select: none;">No file selected</span>
<span class="action" style="-moz-user-select: none;">Select</span>
</div>
Still no idea what's going on, but this is the end result.
I build your page using play-1.2.3 and uniform-2446d99, and in ff 3.6.20 it seems to work fine here. What version of play! are you using?
精彩评论