Load loads the provided data into the form and the related record.
(data map[string]any)
| 87 | |
| 88 | // Load loads the provided data into the form and the related record. |
| 89 | func (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 | |
| 128 | func (form *RecordUpsert) validateFormFields() error { |
| 129 | isAuth := form.record.Collection().IsAuth() |