Is it possible to "require" a file?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to "require" a file?

Lee Hart
Hi

I'm trying to make the file fields on my forms required, using something like this within the xforms:model:

<xforms:bind nodeset="instance('ins-upload')/media" required="true()" />

...which seems to bind properly with the form, i.e. something like:

<xforms:upload ref="instance('ins-upload')/media">
<xforms:label>File: </xforms:label>
<xforms:filename ref="@filename"/>
<xforms:mediatype ref="@mediatype"/>
<xxforms:size ref="@size"/>
<xforms:alert>Please select a file.</xforms:alert>
</xforms:upload>

...and even presents the usual alert icon, indicating that it is a required field.

I have a control mechanism, that I use to determine whether something is valid, which works something like this (in the model):

<xforms:instance id="ins-control">
<control xmlns="">
<upload-is-valid/>
</control>
</xforms:instance>  

<xforms:action ev:event="xxforms-invalid" ev:observer="ins-upload">
<xforms:setvalue ev:event="xforms-value-changed" ref="instance('ins-control')/upload-is-valid">false</xforms:setvalue>
</xforms:action>
<xforms:action ev:event="xxforms-valid" ev:observer="ins-upload">
<xforms:setvalue ev:event="xforms-value-changed" ref="instance('ins-control')/upload-is-valid">true</xforms:setvalue>
</xforms:action>

However, when I press the trigger, the fact that I haven't provided a file is still ignored. Is this something to do with browser security restrictions, I wonder?

The trigger looks something like this:

<xforms:trigger>
<xforms:label>Upload</xforms:label>
<xforms:action ev:event="DOMActivate" if="../upload-is-valid = 'true'">
<xforms:send submission="sub-post-upload"/>
</xforms:action>
<xforms:action ev:event="DOMActivate" if="not(../upload-is-valid = 'true')">
<xforms:message>Please complete all required fields.</xforms:message>
</xforms:action>
</xforms:trigger>



Does anyone have any explanation or advice on this, or a workaround? Ideally I'd like to prompt the user to select a file using a dialogue message, if they haven't already done so.

Best regards,
Lee






--
You receive this message as a subscriber of the [hidden email] mailing list.
To unsubscribe: mailto:[hidden email]
For general help: mailto:[hidden email]?subject=help
OW2 mailing lists service home page: http://www.ow2.org/wws