Ofbiz: one form with two submit button with two different targets

Viewed 359

Ofbiz offers forms written in xml:

partyForm.xml: 

<form name="AddPartyNote" type="single" target="createPartyNote"
    focus-field-name="noteId" header-row-style="header-row" default-table-style="basic-table">
    <auto-fields-service service-name="createPartyNote"/>
    <field name="partyId"><hidden/></field>
    <field name="noteId" tooltip="${uiLabelMap.PartyOptional}"><hidden/></field>
    <field name="noteName" title="${uiLabelMap.FormFieldTitle_noteName}" tooltip="${uiLabelMap.PartyOptional}"> </field>
    <field name="note"><textarea cols="70" rows="10"/></field>
    <field name="submitButton" title="${uiLabelMap.CommonSave}" widget-style="smallSubmit"><submit button-type="text-link"/></field>
    <field name="cancelLink" title=" " widget-style="smallSubmit">
        <hyperlink target="${donePage}" also-hidden="false" description="${uiLabelMap.CommonCancelDone}">
            <parameter param-name="partyId"/>
        </hyperlink>
    </field>
</form>

For each form there is a submit button and most likely few other buttons such as cancel, update etc..

The form above serves to add a note. in order for this to happen it calls the service and the target createPartyNote.

I created to new service called createPartyNoteAndNotify, and the same for a target.

now I need to add a new button called save and notify

which does the same as the save button: <field name="submitButton" title="${uiLabelMap.Common..... from the above but with different target and service (the new ones createPartyNoteAndNotify)

I tried the following:

<auto-fields-service service-name="createPartyNoteAndNotify"/>
<field name="submitAndNotifyButton" title=" " widget-style="smallSubmit"><submit button-type="text-link"/></field>

and many more ways with no success.

How to add one more button to a form which serves an other purpose?

2 Answers

You can achieve this by using alt-target and use-when condition. Also the button can be shown or hide using use-when. Please look for the similar code mentioned below in the same file PartyForms.xml

`<alt-target use-when="${your_condition}" target="${your_target}" ..../>`

`<field name="${field_name}" use-when="${your_condition}" ..... />`

I would suggest creating another form with target createPartyNoteAndNotify along with it having only hidden fields.
Include that form in the screen.
Now add a field in above form such that

<field name="notify" title=" " widget-style="buttontext">
            <hyperlink description="save and notify" target="javascript:(document.formname.submit())" also-hidden="false" target-type="plain"/>
</field>

where formname will be the name of the new form included.

You can also use Apache OFBiz user mailing list for such queries.

HTH

Related