Do not use any form control inputs while submitting the form using GET method (at least for now
there is no practical use of form control options in GET requests).
Use GET requests to fetch multiple data for tables using Query model, or to fetch
single Input entity (usually just passing its ID) while defining link to the edit form.
Query models always connected with the List models. When defining the List model in your
template,
GOERP will make request to the related API and fetch data based on the Query parameters.
<formmethod="get"id="query-form"><labelfor="query-parameter-1">Query parameter 1:</label><inputtype="text"id="query-parameter-1"name="Api.ModelQuery.Field"value="{{ .Data.Api.ModelQuery.Field }}"><labelfor="query-parameter-2">Query parameter 2:</label><inputtype="text"id="query-parameter-2"name="Api.ModelQuery.AnotherField"value="{{ .Data.Api.ModelQuery.AnotherField }}"><buttontype="submit">Find</button></form><!-- Use List entities to actually apply the query, otherwise Query parameters will be ignored --><ul> {{ range .Data.Api.ModelList }}
<li>{{ .Name }}</li> {{ end }}
</ul>
POST for create and update actions
Let’s take a look into simple create/update example form:
<formmethod="post"id="post-form"><!-- For saving action need to pass only postActionEntity, which will ensure that you are working with correct model --><inputtype="hidden"name="postActionEntity"value="ModelInput"><!-- Optionally, use redirect option to redirect to the specified page after successful saving --><inputtype="hidden"name="postActionRedirect"value="https://erply.com/"><!-- Next 2 fields are related to actual model parameters --><labelfor="input-1">Input 1:</label><inputtype="text"id="input-1"name="Api.ModelInput.Field"value="{{ .Data.Api.ModelInput.Field }}"><labelfor="input-2">Input 2:</label><inputtype="text"id="input-2"name="Api.ModelInput.AnotherField"value="{{ .Data.Api.ModelInput.AnotherField }}"><buttontype="submit"id="save">Save</button></form>
Often we need to make reference from the list of rows to the specific entity edit form. In this case
pass entity ID from the selected row to the edit link by attaching it to the Input ID (some input
models doesn’t have Input suffix, but you can check in data source definitions in editor if model
have “write” option):
<!-- Use built-in .Session object to access account related configuration --><!-- Use prefix '$' if linking made inside the range loop, otherwise omit it --><ahref="/{{ $.Session.ClientCode }}/{{ $.Session.Language.Code }}/example-page?Api.ModelInput.Id={{ .Id }}"target="_self"class="table-action-button"><iclass="button nowrap button--transparent icon-Edit-Line"></i></a>
POST for delete action
Delete actions should be made by following next steps:
Form must have method parameter set to POST
Inside the form set hidden postAction input to delete
Inside the form set hidden postActionIds input to entity IDs (separated by comma) that should be
deleted (using custom JS or predefined goerp components)
Inside the form set hidden postActionEntity input to the entity name that should be deleted. If
it is row in the table, then that entity should have suffix List (e.g. WarehouseDtoList
or WarehouseDtoList). If deleting from the single entity edit form, then suffix may be Input
or just model name, check data sources definition in the editor for exact model names. Please
note, postActionEntity value shouldn’t have API definition, just model name.
<formmethod="get"id="entity-table-id"><inputtype="hidden"name="postAction"value="delete"><inputtype="hidden"name="postActionIds"value=""><inputtype="hidden"name="postActionEntity"value="ModelList"><!-- Add submit button if delete modal not used --><!-- <button type="submit">DELETE</button>--></form><!-- and then somewhere in the list range --><ul> {{ range .Data.Api.ModelList }}
<li>{{ .Name }}</li><!-- If used delete-confirm-partial component, then define next parameters inside the button --><buttondata-form-id="entity-table-id"data-delete-identifier="{{ .Id }}"data-post-action-entity="ModelList"class="button button--transparent nowrap table-action-button action-row-red form-delete-button"><iclass="icon-Trash-Empty-NotFilled"></i></button> {{ end }}
</ul><!-- As an option, somewhere in the end of the page import delete-confirm-modal from goerp components and use it --><!-- to delete one or many entities. Or write your own deletion logic -->{{ template "delete-confirm-partial" .}}