discourse/app/assets/javascripts/admin/addon/models/user-field.js
chapoi c79c5566d1
DEV: add text area option to custom user fields (#34072)
Meta feature request
https://meta.discourse.org/t/is-it-possible-to-have-a-multi-line-longer-text-field-in-the-signup-form/257642/7

This commit adds the option to use a textarea as a custom field:
<img width="1430" height="1520" alt="CleanShot 2025-08-04 at 19 06
45@2x"
src="https://github.com/user-attachments/assets/f827a473-1493-479a-903f-cc2b719e5e87"
/>

### Shown on profile:
<img width="690" height="433" alt="image"
src="https://github.com/user-attachments/assets/c9f386a3-0ca9-4402-9f4e-c3564f347a1c"
/>

### Shown on usercard (not particularly recommended):
<img width="1300" height="670" alt="CleanShot 2025-08-04 at 19 07 22@2x"
src="https://github.com/user-attachments/assets/a9b981cb-afd2-4402-a350-553604b5d070"
/>

### Shown on signup screen
<img width="976" height="1404" alt="CleanShot 2025-08-04 at 19 41 17@2x"
src="https://github.com/user-attachments/assets/548b0bd5-fc6f-4300-94a5-ff1d945a1f43"
/>
2025-08-04 22:12:37 +02:00

39 lines
1.1 KiB
JavaScript
Vendored

import { tracked } from "@glimmer/tracking";
import EmberObject from "@ember/object";
import { i18n } from "discourse/lib/computed";
import RestModel from "discourse/models/rest";
export default class UserField extends RestModel {
static fieldTypes() {
if (!this._fieldTypes) {
this._fieldTypes = [
UserFieldType.create({ id: "text" }),
UserFieldType.create({ id: "textarea" }),
UserFieldType.create({ id: "confirm" }),
UserFieldType.create({ id: "dropdown", hasOptions: true }),
UserFieldType.create({ id: "multiselect", hasOptions: true }),
];
}
return this._fieldTypes;
}
static fieldTypeById(id) {
return this.fieldTypes().findBy("id", id);
}
@tracked field_type;
@tracked editable;
@tracked show_on_profile;
@tracked show_on_user_card;
@tracked searchable;
@tracked requirement;
get fieldTypeName() {
return UserField.fieldTypes().find((ft) => ft.id === this.field_type).name;
}
}
class UserFieldType extends EmberObject {
@i18n("id", "admin.user_fields.field_types.%@") name;
}