Search code examples
moqui

Forms that span multiple entites


I am trying to create a single form that creates a product and also adds a SKU but I have not found an example that helps me out so far.

What I am trying to build is a form-single with three text-line/area fields for the values to be input by the user, while I am able to save values for the productName and the description correctly the idValue unsurprisingly does not save. I have tried including the full entity path in the field name but this also does not work.

Any suggestions or pointers to existing examples would be gratefully received!

<?xml version="1.0" encoding="UTF-8"?>
<screen xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/xml-screen-1.5.xsd">

<parameter name="productId"/>

<transition name="newProduct">
    <default-response url=".">
        <parameter name="productId" value=""/>
    </default-response>
</transition>
<transition name="createProduct">
    <service-call name="create#mantle.product.Product"/>
    <default-response url="."/>
</transition>
<transition name="updateProduct">
    <service-call name="update#mantle.product.Product"/>
    <default-response url="."/>
</transition>

<widgets>
    <form-single name="CreateProduct" transition="createProduct">
        <field name="productName"><default-field><text-line/></default-field></field>
        <field name="description"><default-field><text-area/></default-field></field>
        <field name="idValue"><default-field><text-line></text-line></default-field></field>
        <field name="submitButton"><default-field title="Create"><submit/></default-field></field>
    </form-single>
</widgets>
</screen>

Solution

  • Just create a service that takes input parameters matching the form fields, and have that service do the needful. There are various examples of this in HiveMind and Mantle, including the various task create forms in HiveMind that use the mantle.work.TaskServices.create#Task service.

    Here is the TaskServices.xml file with that service definition:

    https://github.com/moqui/mantle/blob/master/mantle-usl/service/mantle/work/TaskServices.xml

    Here is a screen with a form (NewTaskForm) that calls this service through the createTask transition:

    https://github.com/moqui/HiveMind/blob/master/screen/HiveMindRoot/Task/FindTask.xml

    This is a general pattern with Moqui: create a service that has input parameters that match form fields. When you do this there are even various constraints from the service input parameters that are automatically enforced by JavaScript in the browser (i.e. client and server side validation with a single definition).

    There are more details about all of this in the Making Apps with Moqui book (which you can download from moqui.org).