# Smart Action checkbox defaultValue

**URL:** https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761
**Category:** Help me!
**Created:** [June 23, 2021, 8:26am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761 "2021-06-23T08:26:43Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)
#### Post date: [June 23, 2021, 8:26am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/1 "2021-06-23T08:26:43Z")

</div>

In a smart action, I have a checkbox which I want to check **false** by default.  
But this below doesn’t seem to work, it remains unchecked.

```javascript
{
    name: 'Ajouter un contrat de maintenance',
    type: 'single',
    fields: [{
      ...
    }, {
      field: 'Tacite reconduction',
      type: 'Boolean',
      defaultValue: false
    }, {
      ...
    }]
  }

```

---

<div class="post-metadata">

### Author: ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)
#### Post date: [June 23, 2021, 5:18pm UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/2 "2021-06-23T17:18:36Z")

</div>

Hello @JeremyV,

Could you tell me which version of `forest-express-sequelize` or `forest-express-mongoose`, you use?  
I’ve just tried with the latest, and add no issues.  
You should see something like:  
 ![Capture d’écran 2021-06-23 à 19.18.17](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/5/5cd8bc7d599bc31f34250470ab90cae03c3a24f5.png)

Tell me if you get this.

Cheers,

---

<div class="post-metadata">

### Author: ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)
#### Post date: [June 25, 2021, 3:02pm UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/3 "2021-06-25T15:02:51Z")

</div>

```
"forest-express-sequelize": "^7.6.3",
```

---

<div class="post-metadata">

### Author: ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)
#### Post date: [June 25, 2021, 3:34pm UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/4 "2021-06-25T15:34:28Z")

</div>

Is it possible for you to test with the last version `7.11.3`?

What do you get visually speaking?

---

<div class="post-metadata">

### Author: ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)
#### Post date: [June 28, 2021, 7:51am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/5 "2021-06-28T07:51:12Z")

</div>

I upgraded to 7.11.3 and I still have this:

![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/c/cc7bc6f06aa6ec7e3b3a7dd358b47114d8e23454.png)

---

<div class="post-metadata">

### Author: ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)
#### Post date: [June 28, 2021, 9:05am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/6 "2021-06-28T09:05:09Z")

</div>

Could you share with me which database you are using?  
And how the the column is defined from an SQL point of view, please?

---

<div class="post-metadata">

### Author: ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)
#### Post date: [June 28, 2021, 9:19am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/7 "2021-06-28T09:19:14Z")

</div>

I use a remote postgreSQL DB.

 ![image](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/e/ee74501b725636d5f6be87b068d09e689d0ea741.png)

---

<div class="post-metadata">

### Author: ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)
#### Post date: [June 28, 2021, 3:03pm UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/8 "2021-06-28T15:03:01Z")

</div>

Hello @JeremyV,

It is weird indeed.  
Do you have defined any hooks on this smart action?  
Could I get your whole smart action definition, please?

Thank you,

---

<div class="post-metadata">

### Author: ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)
#### Post date: [June 28, 2021, 3:15pm UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/9 "2021-06-28T15:15:14Z")

</div>

Here you are:

```javascript
{
    name: 'Ajouter un contrat de maintenance',
    type: 'single',
    fields: [{
      field: 'Type de contrat',
      type: 'Enum',
      enums: [
        'Maintenance',
        'Assurance'
      ],
      isRequired: true
    }, {
      field: 'Catégorie de contrat',
      type: 'Enum',
      enums: [],
      isRequired: true
    }, {
      field: 'Clé de répartition',
      type: 'Enum',
      enums: [],
      isRequired: true
    }, {
      field: 'N° de contrat',
      type: 'String',
      isRequired: true
    }, {
      field: 'Date de début',
      type: 'Dateonly',
      isRequired: true
    }, {
      field: 'Date de fin',
      type: 'Dateonly',
      isRequired: true
    }, {
      field: 'Préavis en jours',
      type: 'Number',
      isRequired: true
    }, {
      field: 'Tacite reconduction',
      type: 'Boolean',
      defaultValue: false
    }, {
      field: 'Montant annuel TTC',
      type: 'Number',
      isRequired: true
    }, {
      field: 'Commentaire',
      type: 'String'
    }, {
      field: 'Périodicité du contrat d\'assurance',
      type: 'Enum',
      enums: [
        'Mensuelle',
        'Trimestrielle',
        'Annuelle'
      ]
    }, {
      field: 'Recherche fournisseur (3 lettres minimum)',
      type: 'String'
    }, {
      field: 'Fournisseur',
      type: 'Enum',
      enums: [],
      isRequired: true
    }, {
      field: 'PJ du contrat',
      type: 'File',
      isRequired: true,
      description: 'PDF uniquement'
    }],
    hooks: {
      load: ({ fields, record }) => models.repartitionKeys.findAll({
        where: { place_id: record.id }
      }).then(repartitionKeys => {
        fields['Clé de répartition'].enums = repartitionKeys
          .sort(
            (a, b) => {
              if (a.letter < b.letter) { return -1; }
              if (a.letter > b.letter) { return 1; }
              return 0;
            })
          .map(repartitionKey =>
            `${repartitionKey.id} - ${repartitionKey.letter}` +
            (repartitionKey.displayName ? ` - ${repartitionKey.displayName}` : '') +
            (repartitionKey.feesTotal ? ` - ${repartitionKey.feesTotal}` : ''));

        return models.maintenanceContractCategories.findAll()
          .then(result => {
            fields['Catégorie de contrat'].enums = result.sort(
              (a, b) => {
                if (a.displayName < b.displayName) { return -1; }
                if (a.displayName > b.displayName) { return 1; }
                return 0;
              }).map(category => {
                return `${category.displayName.toUpperCase()} - ${category.id}`
              });
            return fields;
          });
      }),
      change: {
        ['Recherche fournisseur (3 lettres minimum)']: ({ fields, record }) => {
          if (fields['Recherche fournisseur (3 lettres minimum)'].value.length > 2) {
            return axios.get(`${API_URL}/forest_admin/sage_providers`, {
              headers: {
                'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,
                'X-CURRENT-USER-EMAIL': process.env.SERVICE_EMAIL
              },
              params: {
                place_id: '',
                provider_name: fields['Recherche fournisseur (3 lettres minimum)'].value,
                siret: '',
                matricule: ''
              }
            }).then(res => {
              if (res.data && res.data.length > 0) {
                fields['Fournisseur'].enums = res.data.map(provider => `${provider.matricule} - ${provider.raison_sociale} - ${provider.site_ville}`)
              }
              return fields;
            });
          }
          return fields;
        }
      }
    }
  }

```

---

<div class="post-metadata">

### Author: ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)
#### Post date: [June 28, 2021, 3:55pm UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/10 "2021-06-28T15:55:22Z")

</div>

Does it work if you comment the `hooks` part?

---

<div class="post-metadata">

### Author: ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)
#### Post date: [June 29, 2021, 8:46am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/11 "2021-06-29T08:46:35Z")

</div>

It does work when I remove the `hooks` part ! Should I set the defaultValue in my hooks script ?

---

<div class="post-metadata">

### Author: ![Guillaume\_Cisco](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/guillaume_cisco/32/918_2.png) [@Guillaume\_Cisco](https://community.forestadmin.com/u/Guillaume_Cisco)
#### Post date: [June 29, 2021, 10:05am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/12 "2021-06-29T10:05:19Z")

</div>

Hello @JeremyV,

I have been able to reproduce the issue with a load hook.  
We will fix it and let you know when a new version will be available.

Thanks for your support! 😃

---

<div class="post-metadata">

### Author: ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)
#### Post date: [June 30, 2021, 9:37am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/13 "2021-06-30T09:37:36Z")

</div>

Hey @JeremyV 👋

I would happy happy to know where you did find a reference to this `defaultValue` attribute (If you remember - but I’m guessing in the v6 documentation maybe?).

Support for `defaultValue` was dropped in v7 then re-introduced to fulfill the fact that the hook feature was not enabled for bulk/global smart action, but hooks should be the way to go for the type `single`. It was in fact introduced in v7 especially for this kind of application.

In the `load` hook, you should be able to directly set the `value` of the field, instead of relying on `defaultValue`.

Since the deprecation was not clear enough in the v7 release, we will still support it in the next release & we will add a deprecation warning on this. Since it is not documented anymore, I would still highly suggest to switch to hooks exclusively for `single` smart actions.

If anything is not working as expected with the hook feature (setting values, etc), feel free to ask, and I’ll take a look at the contribution Guillaume made to fix this issue in the meantime.

---

<div class="post-metadata">

### Author: ![JeremyV](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jeremyv/32/1033_2.png) [@JeremyV](https://community.forestadmin.com/u/JeremyV)
#### Post date: [July 1, 2021, 6:57am UTC](https://community.forestadmin.com/t/smart-action-checkbox-defaultvalue/2761/14 "2021-07-01T06:57:49Z")

</div>

Thanks for your insight @anon39848301

TBH I have no certainty about where I found the defaultValue field originally.  
It might have been in the v6 documentation, or in the .forest-admin-schema.json file.

```javascript
{
        "field": "Tacite reconduction",
        "type": "Boolean",
        "defaultValue": false,
        "enums": null,
        "isRequired": false,
        "reference": null,
        "description": null,
        "position": 7,
        "widget": null
      },

```

I took the habit to have a look at the file to check my available options.
