cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically submit a form

soulpower
Champ in-the-making
Champ in-the-making
Hi,
I'd like to know if there's a way for programmatically submit a form - generated with the "new Alfresco.formUI(…)" constructor - without involving the user click on the submit button.
In classic javascript it could be document.forms["form_id"].submit() but this doesn't work for Alfresco's forms (error from the server).
I've tried to simulate the "click" event to the submit button with the YUI libraries, but it seems too much complicated for me.
Please help!

Thanks,
Roberto
3 REPLIES 3

soulpower
Champ in-the-making
Champ in-the-making
I've solved in a far from elegant way, that involves modifying the forms-runtime js.

The idea is to call the _submitInvoked function, but to do this I need the formUI instance inside the scope of my script. So I've modified the forms-runtime script to set a my script's var to "this" (that is the formUI instance itself). So from my script I call myvar._submitInvoked() and it works.

QUESTION: how I could get the formUI instance visible in my scope without modifying the core script?

Thanks,
Roberto

zaizi
Champ in-the-making
Champ in-the-making
Programmatically submitting a form is a bad design approach. Why do you have to do that?

Ainga

soulpower
Champ in-the-making
Champ in-the-making
Hi zaizi, thanks for the reply!

The customer wants to upload a content and set the content's metadatas within the same form. By now, Alfresco allows to separately set metadatas by clicking "edit metadata" once the file has been uploaded.

So I've customized the upload interface by putting the custom form inside the upload panel (using component/form service). Obviusly in this way I have 2 submit buttons: one for the upload task, and one for the custom form. I've chosen to hide the last one (with css). By clicking on the upload button, the file is loaded into the repository and, FORTUNATELY, the flash-upload components retrieves the nodeRef of the uploaded content. In this moment I've to fire the custom form submit, in a programmatic way.

How do you could do this instead?

Thanks again.

Roberto