Skip to content

Conditional logic and the frontend script

The Logic tab with show and require rules

The Logic tab lists every rule of the form in one place, for example “Show Message when Topic equals Sales”.

  • Effect: show, hide, require or disable a field.
  • Match: the rule applies when all of its conditions match, or when any of them matches.
  • Condition: the field to check, an operator and a value. The editor only offers operators that make sense for that field type. For example, a checkbox can be ticked or not ticked, and a number can be greater or less than a value. Select and radio fields offer their choices as values.
  • When rules depend on each other in a loop, the tab warns you. The server refuses to save such a loop.

The rules are stored on the field they change (fields[].conditions).

public/frontend/pimkit-forms.min.js is plain TypeScript with no framework, about 5 KB gzip. The build fails if it grows past 12 KB. The first form on a page loads it automatically. It starts every <form data-pimkit-form> on the page.

  • Live conditions: the browser uses the same rules as the server (assets/frontend/src/conditions.ts, a port of ConditionEvaluator). Both pass the shared fixtures in tests/fixtures/conditions/. Hidden and disabled fields are disabled in the form, so their values are not sent. “(required)” appears and disappears with the “require” effect.
  • Checks before sending: required, length, email, number and date ranges, pattern, ticked boxes, and file count, size and type. Messages come from the Symfony translations in the page language (data-pimkit-messages). Errors appear next to the fields and in a summary at the top, which receives focus. A field’s error goes away as soon as it is fixed.
  • AJAX submit: the form is posted with FormData to the same URL as without JavaScript, asking for JSON. On success, the form is replaced by the success message, or the page is redirected when the form says so. Server errors (422) appear the same way as the checks in the browser. Network problems show a message, and the visitor’s input stays.
  • Files: each file input gets a drop zone and a list of the chosen files. A progress bar shows while files upload.
  • Without JavaScript, the form still works as a normal post (see Submitting forms).

Both events bubble from the form, and event.detail.form holds the form name.

Event When detail
pimkit:form:submitted The server accepted the submission form, uuid
pimkit:form:step A multi-step form showed another step form, step (from 0), steps
pimkit:form:error Checks failed, the server said no, or the network failed form, reason (validation, invalid, server, network), fields or status
document.addEventListener('pimkit:form:submitted', (event) => {
console.log('Sent', event.detail.form, event.detail.uuid)
})
config/packages/pimkit_forms.yaml
pimkit_forms:
frontend_script: true # false: include pimkit-forms.min.js yourself, e.g. in your build
data_layer: false # true: also push pimkit_form_submitted / pimkit_form_error to window.dataLayer (GTM)

A single form can opt out of the script tag with {{ pimkit_form('contact', {script: false}) }}. Forms added to the page later, for example in a modal, start with window.PimKitForms.init(container).

Terminal window
cd assets/frontend
npm install
npm test # Vitest: the shared condition fixtures and DOM tests on the plain theme's real HTML
npm run check-types
npm run build # writes public/frontend/pimkit-forms.min.js (committed) and checks the size

End-to-end check against a running sandbox: node tests/e2e/frontend-forms.e2e.cjs.