I want to validate a form that only contain one UploadItem. I have been used validators in other forms that are filled with datasouces, but this method doesn’t work in forms that contain uploaditem.
Where is the problem? What’s the solution?
DynamicForm.create({
numCols : 4,
layoutAlign : "center",
encoding : "multipart",
action : "someAction.action",
canSubmit : true,
ID : "contactsForm",
fields : [
{title : "Choose File",name : "upload", editorType : "upload", required : "true", wrapTitle :false },
{name: "validateBtn", title: "upload", type: "button", click:"someFunction()", startRow : false}
// {title : "upload", editorType : "submit", startRow : false}
]
})
Hi Mehdi,
What sort of validation would you apply to an upload field? Are you just trying to ensure that it is non-empty?
What issue are you seeing when you attempt to validate()?
hi
i try to ensure that upload item is not empty. i use validate() but my form submitted without validation and rise error.
Hi Mehdi
You should be able to set an upload item as required, in which case, calling ‘validate()’ on the form in question will fail (by showing validation errors and returning false) if the upload item is empty.
However you should be aware that redrawing a DynamicForm containing an upload item will cause the value of the item to be lost, and when validation errors are shown for a form, this is done via a redraw. In other words, showing validation errors for a form will clear out the value of any upload items in the form.
We’ve added some documentation to the UploadItem class for 5.7 to cover this:
“if a form containing an UploadItem is redrawn (which may happen if other form items are shown or hidden, the form is resized, or other items show validation errors) then the value in the upload item is lost (because an HTML upload field may not be created with a value). For this reason, if you are building a form that combines an UploadItem with other FormItems that could trigger redraw()s, recommended practice is to place each UploadItem in a distinct DynamicForm instance and create the visual appearance of a single logical form via combining the DynamicForms in a Layout.”
If you continue to have trouble getting this working, let us know (possibly posting a simple code sample demonstrating the problem you’re seeing)
Thanks
Isomorphic Software