Advanced Attribute Editing

This sample uses the FeatureForm widget to update attributes of existing features by calling the applyEdits function when a user selects a feature on the view.

Instead of displaying all of the specified fields in various form elements, certain fields display based on whether they meet a specified condition. It does this using the visibilityExpression property found on both FieldElement and GroupElement classes. This property takes an Arcade expression, and if it resolves to true, the field renders within the form.

The first field element displays a field labeled Issue status. If the value is Completed and the Resolution field is not empty, the second field labeled Resolution will display. Based on the status field, one or two grouped fields display.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72

const expressionInfos = [{
  name: "field-resolution",
  expression: "($feature:any.status == 'Completed') && (!(IsEmpty($feature:any.resolution)))"
}, {
  name: "category-AnimalProbType",
  expression: "$feature:any.category == 'Animal'"
}, {
  name: "category-BlightProbType",
  expression: "$feature:any.category == 'Blight'"
}, {
  name: "group-update",
  expression: "($feature:any.status == 'Submitted') || ($feature:any.status == 'Received')"
}];

// This snippet sets individual field elements within the form's template
// Individual field elements to display
const fieldStatus = new FieldElement({
  fieldName: "status",
  editable: false,
  label: "Issue status",
  description: "E.g. submitted, received, in progress, or completed.",
});

const fieldResolution = new FieldElement({
  fieldName: "resolution",
  label: "Resolution",
  editable: false,
  description: "Resolution if status is set to Completed",
  visibilityExpression: "field-resolution",
});

// The following sets field elements and passes it into a group element

const fieldCat = new FieldElement({
  fieldName: "category",
  label: "Category"
});

const fieldAnimal = new FieldElement({
  fieldName: "AnimalProbType",
  label: "Animal problem type",
  visibilityExpression: "category-AnimalProbType",
  description: "E.g. barking dog, bite, etc."
});

const fieldBlight = new FieldElement({
  fieldName: "BlightProbType",
  label: "Blight problem type",
  description: "E.g. graffiti, abandoned vehicle, etc.",
  visibilityExpression: "category-BlightProbType"
});

//Create the group element and pass in the field elements from above
const groupUpdate = new GroupElement({
  label: "Update issue",
  description: "If work has not yet begun on issue, categorize and detail the problem",
  visibilityExpression: "group-update",
  elements: [fieldCat, fieldAnimal, fieldBlight]
});

// Create the feature form and pass in the elements from above into the form template
const form = new FeatureForm({
  container: "form",
  groupDisplay: "sequential",
  formTemplate: {
    title: "Report issues",
    description: "Provide information to the questions below",
    elements: [fieldStatus, fieldResolution, groupUpdate, groupPOC],
    expressionInfos: expressionInfos
  }
});

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.