MCPcopy
hub / github.com/pocketbase/pocketbase / Load

Method Load

forms/record_upsert.go:89–126  ·  view source on GitHub ↗

Load loads the provided data into the form and the related record.

(data map[string]any)

Source from the content-addressed store, hash-verified

87
88// Load loads the provided data into the form and the related record.
89func (form *RecordUpsert) Load(data map[string]any) {
90 excludeFields := []string{core.FieldNameExpand}
91
92 isAuth := form.record.Collection().IsAuth()
93
94 // load the special auth form fields
95 if isAuth {
96 if v, ok := data["password"]; ok {
97 form.password = cast.ToString(v)
98 }
99 if v, ok := data["passwordConfirm"]; ok {
100 form.passwordConfirm = cast.ToString(v)
101 }
102 if v, ok := data["oldPassword"]; ok {
103 form.oldPassword = cast.ToString(v)
104 }
105
106 excludeFields = append(excludeFields, "passwordConfirm", "oldPassword") // skip non-schema password fields
107 }
108
109 for k, v := range data {
110 if slices.Contains(excludeFields, k) {
111 continue
112 }
113
114 // set only known collection fields
115 field := form.record.SetIfFieldExists(k, v)
116
117 // restore original value if hidden field (with exception of the auth "password")
118 //
119 // note: this is an extra measure against loading hidden fields
120 // but usually is not used by the default route handlers since
121 // they filter additionally the data before calling Load
122 if form.accessLevel != accessLevelSuperuser && field != nil && field.GetHidden() && (!isAuth || field.GetName() != core.FieldNamePassword) {
123 form.record.SetRaw(field.GetName(), form.record.Original().GetRaw(field.GetName()))
124 }
125 }
126}
127
128func (form *RecordUpsert) validateFormFields() error {
129 isAuth := form.record.Collection().IsAuth()

Callers 10

recordCreateFunction · 0.95
recordUpdateFunction · 0.95
TestRecordUpsertLoadFunction · 0.95
DrySubmitMethod · 0.45

Calls 8

IsAuthMethod · 0.80
CollectionMethod · 0.80
SetIfFieldExistsMethod · 0.80
SetRawMethod · 0.80
GetRawMethod · 0.80
OriginalMethod · 0.80
GetHiddenMethod · 0.65
GetNameMethod · 0.65