Parsware
All articles

Model-driven apps

Choose the control a field uses

A field's type decides what it stores. Its control decides how people fill it in. Turn a yes-or-no field into a switch with its own words, show a date in the Persian calendar, and put a control you built yourself on a form.

An asset record in dark mode with an In Service switch and a hand-drawn signature in a Received Signature box, next to the title "Choose the control a field uses"

The same field can be filled in more than one way. A yes-or-no field can be a checkbox or a switch. A date can be written in the Gregorian calendar or the Persian one. And some fields need something the platform doesn't ship, such as a box to sign in.

In Required, read-only and default controls we gave a field a default control, used on every form. This article sets the control on one form only. We carry on with the Asset table's Information form from Forms that fit the job. Every picture is the real product.

A switch with its own words

Open the form in the Form Designer and select In Service. The Control list offers the controls that suit a yes-or-no field: Check and Toggle. It starts on Default (Check), which means it follows the field.

Choose Toggle. Two more boxes appear, Yes label and No label: the words shown beside the switch. We used In service and Retired, which say more than Yes and No.

The Form Designer with In Service selected in the Assignment section: Control set to Toggle, Yes label "In service", No label "Retired"

The list only offers controls that fit the field. A text field gets Text and Text Area, a date gets the date controls, and a lookup gets the record picker. You can't give a date a checkbox.

A date in the Persian calendar

On the Purchase tab, select Purchase Date. Its controls are Date, Date and Time and Time, and each has a Persian version. Choose Persian Date.

The Purchase tab in the Form Designer with Purchase Date selected: Control set to Persian Date and an empty Date format box

Naming a calendar here means this field always uses it, whatever the app's calendar setting says. Leave the control on Default and the field follows the app's setting instead (Settings → Calendar), so one switch changes every date in the app.

Date format is optional. Leave it empty and a Persian date is written in full, such as ۲۲ بهمن ۱۴۰۳. The date is stored the same way whichever calendar shows it, so changing the control never changes the data.

A control you built

When no built-in control fits, you can build your own and put it on a field. Custom controls are React components, packed into one file and added to your solution under Custom Controls. Building one gets its own article later in this series; here we use the Signature Pad sample that comes with the platform.

We added a Received Signature field (multiline text, since a signature is stored as a picture written out as text) and placed it under In Service. Select it and a Custom Control list appears below the others, offering the installed controls that can stand in for this field. Choose Signature Pad.

Received Signature selected in the Form Designer: Control Default (Text Area), and Custom Control set to Signature Pad

A custom control replaces the field's own control, so it wins over whatever Control says. If the control isn't installed in an environment, for example because its solution wasn't imported, the field falls back to its own control and the form still works.

What people see

Save the form and open an asset in the app. In Service is a switch that says In service, and whoever takes the laptop signs for it on the form:

The ThinkPad X1 Carbon record: Assigned To Riley Miller, the In Service switch on with the words In service, and a signature drawn in the Received Signature box, marked Signed

The signature is saved with the record like any other value. On the Purchase tab, the purchase date is in the Persian calendar:

The Purchase tab of the same record: Purchase Date reads ۲۲ بهمن ۱۴۰۳ in a date box, and Purchase Cost reads 1849

Two things we fixed while writing this article. Any click inside the signature box used to reach its own Clear button, so a signature was wiped the moment you let go of the mouse. And on an English page a Persian date was shown in the wrong order, with the year before the month. Both work as shown here now.

The choices, as the form stores them

Each choice in this article is a property of the field's placement on the form, not of the field. The Assignment section after the steps above:

{
  "title": "Assignment",
  "fields": [
    { "field": "con_assignedto" },
    {
      "field": "con_inservice",
      "controlType": "Toggle",
      "controlProps": { "trueLabel": "In service", "falseLabel": "Retired" }
    },
    { "field": "con_receivedsignature", "control": "par_signature_pad" }
  ]
}

controlType picks one of the platform's own controls, and controlProps holds what that control can be told, here its two labels. control names a custom control, which wins over controlType when both are set. A placement with neither, like Assigned To, follows the field's default control.

Because these live on the placement, a second form of the same table can make different choices. The IT team's form can show In Service as a switch with their words, while the purchasing team's form shows a plain checkbox.

Every control the platform ships

The Control list only ever offers controls that fit the field's type. Between them, the platform's own controls cover most needs:

Control Fits What it shows
Text Text A one-line box
Text Area Text, multiline text A taller box for writing
Check Yes/No A checkbox
Toggle Yes/No A switch, with words of your choosing
Date, Date and Time, Time Date/time A calendar, a time picker, or both
Persian Date, Persian Date and Time, Persian Time Date/time The same, in the Persian calendar
Dropdown Option set The set's options, with their colours and icons
Lookup Lookup A search that finds records as you type
Map Decimal A map with a pin, writing a latitude and a longitude
Label No field A note, as in Notes and labels

An Image field's placement also has a size, small, medium or large, for how big its preview is on the form. Small suits a contact's photo beside their name; large suits a product picture people actually need to look at.

A place on a map

The Map control deserves a closer look, because it shows how a control can be more than a nicer box. The platform has no location type: a place is two decimal fields, a latitude and a longitude. The Map control sits on the latitude and names the longitude:

{
  "field": "par_latitude",
  "label": "Location",
  "controlType": "Map",
  "controlProps": {
    "longitudeField": "par_longitude",
    "helperText": "Click the map to move the branch."
  }
}

On the form, the two numbers become one pin. Clicking the map moves the pin and writes both fields, and Save stores them, even though only the latitude is placed on the form. The Branches sample in the platform's sample solutions shows it, with two branches already on the map. The map tiles come from OpenStreetMap unless the installation names its own map server.

Two ways to build your own

When nothing the platform ships fits, there are two ways to make a control, and they suit different people.

  • A drawn control, made in the Application Studio as a Studio app of kind Control. A star rating on a whole-number field is the classic example: five stars drawn on the canvas, each setting the field to its number when pressed. No code beyond one-line expressions. The placement names it as "control": "studio:par_star_rating".
  • A custom control in code, a React component your developers write and pack into one file, like the Signature Pad above. Use this when the control needs a browser feature a drawing can't reach, such as a canvas to sign on or a barcode scanner.

Either way, the control reads the field's value and writes it back into the form, as typing would: the form is marked as changed, Save stores the value and Discard drops it. The record's rules don't change. A required field is still required, and a server rule still checks what is saved. Build a custom control and Put a custom control on a field cover the code route; Components: draw once, use everywhere is the place to start for drawing.

Choosing well

  • Prefer the field's default control. Set a control on one form only when that form's readers need something different. Otherwise set the default on the field, once, and every form follows.
  • Give a toggle words. In service and Retired say what the switch means; Yes and No make people read the field's label again.
  • Leave dates on Default in a mixed audience. A Persian-speaking user then sees Persian dates and an English-speaking user Gregorian ones, from the same record, by their own setting. Pin a calendar only when the document itself is in that calendar, such as a Persian contract date.
  • Keep custom controls for real gaps. Every custom control is code somebody maintains. A star rating drawn in the Studio may be all a form needs.

In short

You want Choose
A switch instead of a checkbox Toggle, with a Yes label and a No label
One date always in the Persian calendar Persian Date (or Persian Date and Time, Persian Time)
Every date to follow the app's calendar Default
A control the platform doesn't have A Custom Control from your solution

The control is saved with the form, so it moves with your solution to Test and Production.

Next: views, the lists people work in.