apostrophecms / apostrophe

A full-featured, open-source content management framework built with Node.js that empowers organizations by combining in-context editing and headless architecture in a full-stack JS environment.
https://apostrophecms.com
Other
4.36k stars 590 forks source link

Unable to change default value for boolean schema field to true #2331

Closed ngranahan closed 3 years ago

ngranahan commented 4 years ago

To Reproduce

  1. Add boolean field to a piece, page, or widget, setting def: true
{
      name: 'example',
      label: 'Example',
      type: 'boolean',
      def: true,
      choices: [
        { label: 'Yes', value: true },
        { label: 'No', value: false }
      ]
}
  1. View field in Apostrophe UI to confirm that default value is still set to false

Expected behavior

Setting def: true in a boolean schema field should set the default value of that field to true.

Describe the bug

Setting def: true does not change the default value of the boolean field to true. Default is always set to false.

boutell commented 4 years ago

I see Bea has assigned this to himself, missed that earlier, but FYI folks, here is a demo where it works:

https://github.com/apostrophecms/apostrophe-boilerplate/tree/boolean-def-demo

Looking at Nora's example, the difference could be the use of the "choices" option perhaps?

boutell commented 4 years ago

I am also unable to reproduce it this way:

      addFields: [
        {
          type: 'boolean',
          name: 'cool',
          def: true,
          choices: [
            { label: 'Yes', value: true },
            { label: 'No', value: false }
          ]
        }
      ]

true is working as the default for me here too.

@ngranahan I think we'll need a branch of apostrophe-boilerplate demonstrating the issue from you to move forward.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

abea commented 4 years ago

theoretically I will be returning to this.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

abea commented 3 years ago

Yeah, I double checked as well with fields:

  addFields: [
    {
      name: 'booleanFalse',
      label: 'False boolean',
      type: 'boolean',
      def: false,
      choices: [
        { label: 'Yes', value: true },
        { label: 'No', value: false }
      ]
    },
    {
      name: 'booleanTrue',
      label: 'True boolean',
      type: 'boolean',
      def: true,
      choices: [
        { label: 'Yes', value: true },
        { label: 'No', value: false }
      ]
    }
  ],

Both default as expected. I'll close until we have some more reproduceable info.