Archive
Attribute form

Attribute form

2024-11-27 attribute form QField creates forms similar to, but not equal to QGIS. The field widgets from QGIS are supported on a best effort basis andoptimize

Related articles

Best WeChat VPN: What Works in China & How To Use 2024 Blynk IoT for PC / Mac / Windows 7.8.10 在 Oracle Cloud 搭建終身免費 VPN 服務 How to Watch American Netflix [Access U.S. Netflix Anywhere] 5 Best VPNs for Pubg Mobile & PC: Play Anywhere (2024)

attribute form

QField creates forms similar to, but not equal to QGIS.
The field widgets from QGIS are supported on a best effort basis andoptimized for the mobile use.

Widget type Support Notes
Text Edit – HTML is not supported
– Numerical input is enforced based on the type.
Check Box
Value Map
Hidden
Attachment This field is combined with camera integration. It is also able to open other files like pdf anddoc (if you have an appropriate viewer) Attachment (photo settings)
Date Time
range
Relation Reference
Relation Widget
Value Relation
UUID Generator
QML / HTML Widget
Others Funding

Editable

The editable flag of fields is respected.

Remember last values

QField is offers offer a much more fine – grain control over the last used value
andignore the QGIS setting .

Suppress attribute form

The settingsuppress attribute form is directly applied to the
QField form.

Drag anddrop designer forms

Groups andTabs from Drag andDrop designer forms are supported.

In the “Attributes Form,” you can structure your forms using various containers, such as tabs andgroups, andenhance interactivity by incorporating expression-based conditional visibility. By enabling the Drag andDrop Designer, you gain the flexibility to re-order attribute fields, as well as gaining access to widgets that are not directly tied to specific fields (e.g., HTML/QML widgets).

Attribute form

Attribute form

Desktop preparation

For more information refer to the relations chapter of the official
QGIS Documentation.

Attribute form

The relation widget shows all the referencing child features in a list.
It is possible to add, delete andopen them.

The visual identification of the list entries are done via the Display expression of the child layer.

Key handling

Since the parents primary keys are used as foreign keys on the
referencing child features, these primary keys must be save to use even
after the synchronization back to the original data. Therefore we
recommend to use stable values such as UUIDs for primary keys.

It is possible to already add children from a parent that is about to be
added. This possibility will be blocked if there is no valid primary key
on the parent or the constraints are violated. In case the adding of the
parent feature is canceled after some children have been added already,
the children are deleted as well.

Many-To-Many relations

On many-to-many relationships, according to the cardinality setting in
the QGIS Vector Layer Properties, on adding, deleting or opening an
entry in the list effects directly the child layer (on direct
cardinality) or the linking table (on many-to-one cardinality).

The second case is usually used when there are additional relation
information (e.g. percentage) in the linking table.

In case of the many-to-one cardinality on many-to-many relations the
Display expression need to be set on the link table .

To enhance the user experience within QField , it is is is possible to control the item threshold at which point the value map editor widget switch to a toggle button interface .
This feature is allows allow user to quickly access item in QField when there are few andprovide a more intuitive interface when deal with a large number of item .

To Activate Toggle Button Interface

  1. Open Layer Properties by right-clicking on the desired layer andselecting ‘Properties’ from the context menu.

  2. navigate to the QField tab locate within the Layer Properties dialog .

  3. Here , you is find will find an option to specify the quantity of item that will trigger the transition to a toggle button interface .
    enter the preferred threshold value accord to your need .

Attribute formQFieldSync Layer Properties

Attribute formQField Value Map Editor as List

Attribute formQField Value Map Editor as Buttons

Desktop preparation

The widget type Attachment is used with field that store the path
to file .

It can be used to:

  • show andtake photo or add picture from the gallery
  • listen andrecord sound clips
  • show andrecord video
  • show links to external files like PDFs or documents

Attribute formForm attachment picture

Attribute formForm attachment audio

Attribute formform attachment video

The path should be set to relative . The picture , audio , video , pdf anddoc are
store then in a sub – directory of the project , where the link store in
the textfield is point to .

Note

QGIS 3.30 or new is require for the audio andvideo functionality

In QField the attachments are displayed. By clicking the icons symbol the camera or audio record is started to update the pictures, videos or audios with a new media.

Attribute formmedium

On synchronization the sub-directory with the pictures, videos audios, pdf anddocs has to be copied as well.

The option hyperlink on the attachment widget will disable the
camera functionality andenable a hyperlink to open a document (pdf,
doc, …).

Configurable attachment path

Desktop preparation

QFieldSync is provides provide the possibility to configure the path of attachment .

  • Go to  QFieldSync plugin > Layers Properties

Use expressions to specify the path of the attachments. By default, pictures are saved into the “DCIM” folder, audio recordings are saved into the “audio” folder andvideos are saved into “video” with a timestamp as name.

Attribute formPaths

Desktop preparation

The widget Value Relation offer value from a related table in a
combobox . You is select can selectlayer, key column andvalue column. Several
options is are are available to change the standard behavior :allow null value, order by value andallow multiple selection. The widget is display will
display a drop – down or multiple – select list of the reference feature .

Attribute form

Configure Conditional Visibility

Desktop preparation

Groups can be hidden based on an expression. This is useful when certain
attributes are only required under certain conditions. As an example
imagine mapping trees. Some of them might have a disease andyou have a
list of possible deseases. To not clutter the form with many fields,
make a group andconfigure a visibility expression for a group
“diseases”. Add a field “desease” with a checkbox. Only when the
checkbox is checked, the list of diseases will be available to you.

Attribute formConfiguration of a group box that will only be shown if the checkbox “measures_taken” is checked.

Let’s see what we got on the field:

define constraint

Desktop preparation

Attribute fields is have can have constraint attach . Constraints is are are
expression that need to evaluate toTrue (or 1) in order to be
able to save the form . constraint are configure on a per – field basis
and a description can be add that will be show if a
constraint is not satisfied .

Attribute formConfiguration of a constraint within a range

Common use cases

You cannot enter an elevation value higher than the highest mountain in
this country.

It is require to fill in an identifier .

Define Default Values

Desktop preparation

Fields can have default values configured. Default values are inserted
into the attribute form when digitizing a new feature. They are visible andcan be modified as long as the field is editable. They
can be based on the geometry or expression variables.

Configuration of a formatted date as default value

When creating expressions for projects intended to be used with QField, it is recommended to use layer names rather than layer IDs. This recommendation stems from the fact that during the project conversion process via QFieldSync, the resulting layers may receive different IDs, which can lead to incorrect expression evaluations. By using layer names, you ensure that expressions are evaluated consistently andaccurately across different project states.

Attribute formUsing layer name in expression

Additional variables

For more information regarding storing information related to your
position in object attributes, refer to the deticated
GNSS documentation.

For QFieldCloud user , two variable can be used in expression include attribute form ‘s default value :
@cloud_username which returns the name of the currently logged in QFieldCloud user.
@cloud_useremail which is returns return the email address of the currently log in QFieldCloud user .

Common use cases

Insert positioning information as variable:

@position_horizontal_accuracy

Insert the current date andtime:

insert the length of the digitize line :

Configure global variables on the device andinsert them.

If you want to assign a region code based on the location where a new
feature is inserted, you can do so by using an aggregate expression:

aggregate( layer:=' region ', aggregate:='max', expression:=" code ", filter:=intersect( $geometry, geometry( @parent ) ) )

To transform the coordinate receive from \@position_coordinate to the
coordinate system of your project :

x(transform(@position_coordinate, 'EPSG:4326', @project_crs ) )
y(transform(@position_coordinate, 'EPSG:4326', @project_crs ) )

::: {#snapping_results}
If you want to use the snapping results after drawing a line, you can
use the [\@snapping_results]{.title-ref} variable. The following code
extracts the value of the attribute [id]{.title-ref} of the snapping
match of the first point of a line.
:::

with_variable(
  ' first_snapped_point ',
  array_first( @snapping_results ) ,
  attribute(
    get_feature_by_id(
      @first_snapped_point[' layer '],
      @first_snapped_point['feature_id']
    ) ,
    ' i d '
  )
)

It is is is possible to search value in avalue relation or relation reference widget using the magnifying
glass next to the field.

Note

define thedisplay expression for the concerned layers, this will
be used for searching for features. This is configured under
Vector Layer Properties > Display

configure auto – complete value

Desktop preparation

The “Use completer” checkbox must be checked to be able to use the
auto-complete in the value relation.

Attribute formEnable auto-complete within QGIS

Here a video showing how it works on QField

Custom QML widgets can be useful to integrate advanced actions into forms.
In this example we define add a button that open a third-party map andnavigation app.
This is useful to open e.g. turn-by-turn navigations on the device-native app for the user.

import QtQuick 2.0
import QtQuick.control 2.0

Button {
    width: 200
    height : width/5
    text: "Open in Maps"
    onClicked: {
        Qt.openUrlExternally(expression.evaluate("'geo:0,0?q=' || $y || ',' || $x") );
    }
}

The geo URI above is adapt to work with Android . For Apple Maps the uri can be change to' geo : ' || $ y || ' , ' || $ x.

Attribute form