# Override custom field

**URL:** https://meta.discourse.org/t/override-custom-field/136985
**Category:** Development
**Created:** [December 24, 2019, 3:08pm UTC](https://meta.discourse.org/t/override-custom-field/136985 "2019-12-24T15:08:29Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [December 24, 2019, 3:08pm UTC](https://meta.discourse.org/t/override-custom-field/136985/1 "2019-12-24T15:08:29Z")

</div>

create-account.hbs

```plaintext
{{#if userFields}}

            <div class='user-fields'>

              {{#each userFields as |f|}}

                {{user-field field=f.field value=f.value}}

              {{/each}}

            </div>

          {{/if}}

```

js

```plaintext
var siteSettings = Discourse.SiteSettings;
    console.log(siteSettings.forum_name);

complete = $(".user-field-" + siteSettings.forum_name);

```

[https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/controllers/create-account.js.es6#L239-L245](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/controllers/create-account.js.es6#L239-L245)

How to check the field?

```plaintext
{{#if f.field.name == complete }} {{! doesn't work }}
  OK
{{/if}}

```

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [December 24, 2019, 4:32pm UTC](https://meta.discourse.org/t/override-custom-field/136985/2 "2019-12-24T16:32:08Z")

</div>

set input for create-account.hbs

```plaintext
 var siteSettings = Discourse.SiteSettings;
          $('.control-label').each( function () {
  if($(this).text().trim() === siteSettings.forum_name) {
  const uuid ='lp'+(()=>([1e7]+-1e11).replace(/[018]/g,c=>(c^crypto.getRandomValues(new Uint8Array(1))[0]&15 >> c/4).toString(16)))();
var id = "user-" + $(this).parent().attr('id');
    var input = $('#' + id);
    input.val(uuid);
   // $(this).parent().hide()
  
    }
})

```

It looks like this

 ![2019-12-24_192915](https://global.discourse-cdn.com/meta/original/3X/5/6/56872794f243acece028705ae440cefd987849db.png)

Rails.logger.warn(“#{params }”)  
It looks like this

```plaintext
"user_fields"=><ActionController::Parameters {"1"=>"true", "2"=>""}

```

“2”=\>“”  
where is the second field ?

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [December 26, 2019, 10:06am UTC](https://meta.discourse.org/t/override-custom-field/136985/3 "2019-12-26T10:06:05Z")

</div>

> [@Dev\_Work](#):
>
> {{#if f.field.name == complete }}

This doesn’t work because you can’t perform the actual logic calculation in a Template. This needs to be handled in the corresponding js by a Computed Property. Be sure to read [the official Ember guides (making sure you select the same version that Discourse uses)](https://guides.emberjs.com/v3.10.0/) and look at the code in one of the many popular #Customization > Plugin on here to provide you with examples.

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [December 26, 2019, 10:12am UTC](https://meta.discourse.org/t/override-custom-field/136985/4 "2019-12-26T10:12:58Z")

</div>

thanks for the answer, I’m interested in examples from plugins

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [December 26, 2019, 10:25am UTC](https://meta.discourse.org/t/override-custom-field/136985/5 "2019-12-26T10:25:00Z")

</div>

Here’s an example of a Computed Property from a PR I recently submitted to Ebsy’s excellent National Flags plugin: [discourse-nationalflags/assets/javascripts/discourse/components/user-nationalflags-preferences.js.es6 at master · Ebsy/discourse-nationalflags · GitHub](https://github.com/Ebsy/discourse-nationalflags/blob/master/assets/javascripts/discourse/components/user-nationalflags-preferences.js.es6)

Here’s one (“_showTimezones_”) that is actually used to hide/show in a template: [https://github.com/paviliondev/discourse-team-timezones/blob/master/assets/javascripts/discourse/components/team-display.js.es6](https://github.com/paviliondev/discourse-team-timezones/blob/master/assets/javascripts/discourse/components/team-display.js.es6)

but you’ll find tonnes of great patterns in our plugins: [Pavilion · GitHub](https://github.com/paviliondev)

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [February 5, 2020, 11:28am UTC](https://meta.discourse.org/t/override-custom-field/136985/6 "2020-02-05T11:28:34Z")

</div>

Hi, I figured out how to override the action in the controllers.

example

```plaintext
import CreateAccount from 'discourse/controllers/create-account';
export default {

    name: 'Create-Account-Popup',
    initialize: function () {
        CreateAccount.reopen({
            actions: {
                createAccount() {
// my code
                }
            }
        });
}

```

How to add your `@discourseComputed` ?

I do as in the example and does not work

```plaintext
export default {
    name: 'Create-Account-Popup',
    
    @discourseComputed()
    ldapForgotPassword() {
        console.log('forgot!!');
        return this.siteSettings.forum_login_popup_use_ldap;
    },

```

> [@Put user custom field on the user account page](https://meta.discourse.org/t/put-user-custom-field-on-the-user-account-page/134090/3):
>
> Ok, I made it work but its somewhat tricky. Create a connector class with this code. import { set } from "@ember/object"; import EmberObject from "@ember/object"; export default { @discourseComputed("model.user\_fields.@each.value") publicUserFields() { const siteUserFields = this.site.get("user\_fields"); if (!isEmpty(siteUserFields)) { const userFields = this.get("model.user\_fields"); return siteUserFields .filterBy("show\_on\_user\_card", true) .sortBy("pos…

---

<div class="post-metadata">

### Author: ![Dev\_Work](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/dev_work/32/124200_2.png) [@Dev\_Work](https://meta.discourse.org/u/Dev_Work)
#### Post date: [February 5, 2020, 11:55am UTC](https://meta.discourse.org/t/override-custom-field/136985/7 "2020-02-05T11:55:20Z")

</div>

Happened through `@computed`

```plaintext
        PreferencesAccount.reopen({
            @computed
            ldapForgotPassword() {
                console.log('forgot!!');
                return this.siteSettings.forum_login_popup_use_ldap;
            },

```

---

<div class="post-metadata">

### Author: ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)
#### Post date: [February 5, 2020, 1:23pm UTC](https://meta.discourse.org/t/override-custom-field/136985/8 "2020-02-05T13:23:46Z")

</div>

> [@Dev\_Work](#):
>
> How to add your `@discourseComputed` ?

You should use this to avoid a browser warning.

It’s just a different import:

```plaintext
import discourseComputed from "discourse-common/utils/decorators";

```
