Assign assign form values back to the template data.
(form any, data map[string]any)
| 38 | |
| 39 | // Assign assign form values back to the template data. |
| 40 | func Assign(form any, data map[string]any) { |
| 41 | typ := reflect.TypeOf(form) |
| 42 | val := reflect.ValueOf(form) |
| 43 | |
| 44 | if typ.Kind() == reflect.Pointer { |
| 45 | typ = typ.Elem() |
| 46 | val = val.Elem() |
| 47 | } |
| 48 | |
| 49 | for i := 0; i < typ.NumField(); i++ { |
| 50 | field := typ.Field(i) |
| 51 | |
| 52 | fieldName := field.Tag.Get("form") |
| 53 | // Allow ignored fields in the struct |
| 54 | if fieldName == "-" { |
| 55 | continue |
| 56 | } else if fieldName == "" { |
| 57 | fieldName = com.ToSnakeCase(field.Name) |
| 58 | } |
| 59 | |
| 60 | data[fieldName] = val.Field(i).Interface() |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | func getRuleBody(field reflect.StructField, prefix string) string { |
| 65 | for _, rule := range strings.Split(field.Tag.Get("binding"), ";") { |
no test coverage detected