Ability to have a default value for a radio button / Boolean field

I had a query on radio buttons and Boolean fields. Currently we can give options Yes and No using these options, but there is no way to default a value for an option and the user has to select an option. Need some help on this, is there a way to default the value to let’s say “Yes” all the time unless someone wants to change the value?

Eg:
Lets say it is a survey question - “Have you given a rating” ( ) yes ( ) No ] - this is how it is shown with the existing fields. Would it be possible to show it like
"Have you given a rating" (X) yes ( ) No Clear ?

9 Likes

Hey @ngandhi ,

First of all, thank you very much for joining our Contentful Community!
Unfortunately, it’s not possible at the moment. What you’re talking about is default values for fields. That’s very useful feature and I completely agree with you. We are aware of that and discussing how we can address it.

Please let me know if I can help you with anything else.

1 Like

I would very much like to see defaults, too.

We also have interest in such feature. Currently with multiple locales we risk to pickup the value of a fallback locale. Which is not desired in our use cases.

Up-voting this feature! Default values would be very helpful.

I second this! Actually, I just sent a feature suggestion to Contentful’s support few days ago.

In this particular case, I had to add a boolean field to a content model which was used for several hundred entries. Going through all those entries manually one by one wasn’t an option, so I had to write a script utilizing the Management API that goes through all the entries of that particular content model and sets the desired value.

My biggest gripe with the boolean field type and the lack of default value is that it’s actually triboolean (true/false/null). Moreover, the way the Web App displays true and null values as “No” is confusing.

I’ll +1 this feature. The triboolean doesn’t make any sense. This is also a very common field type in many other CMS so I imagine most customers are going to expect this type of field.

See this example of “Hide from search?”

Here’s the workaround I came up with. It’s limited to boolean fields and requires that you treat null/undefined as equal to false. In that case, you just have to formulate the field label so that the default condition is met when the field is undefined/null.

Another (mild) workaround is to mark your boolean field as required. That should provide only true/false values, but only for Published entries in the Delivery API. You may still encounter null/undefined values in the Preview API.

Ya, I was planning on doing the same it just sucks that you can’t assign that within the cms already.

Upvote from here as well. Would really love to see default values for fields.

Here is a Default Field value UI Extension which might be useful in this discussion. It is designed for a short text field, but would be easily adapted to boolean fields.

1 Like

Another approach I’ve used with this topic is to create a short text field with a validation of single predefined value and set the appearance to dropdown or radio. That way if the field exists (and is equal to the predefined value) in the API response that represents true and if the field does not exist in the response, that represents false. And the default value of the field is false.

Hey Charlie. I’m trying to use the “Default Field Value” extensions for setting default values on Boolean types, but I can’t figure out for the life of me, how to edit the instance parameters. I even tried creating a new extension, but the params are always read only.

I see in the UI, that I can “set parameter definitions using the Content Management API.”, but that page doesn’t give any info on how to make the API request.

Can you either explain how to update params so I can edit the extension or give us an example on how the extensions can adapted to boolean fields? Thanks

Im in the same position as matt. There simply isnt enough documentation on how to use the api to set instance parameters. And I dont see the point of not allowing us to edit this within contentful itself.

I understand the confusion and I agree with you that it is not clear exactly how to set UI Extensions parameters definitions.

For instance parameters (i.e., variables that are set for each field on which the UI extension is used) those can be set in the webapp directly as shown in this screenshot:

In this case the UI Extension is the Shopify Products UIE and the instance parameters are the access token and the shopify graphql endpoint. These are set for each instance of the UI extension (aka for each field on which the UIE is used).

For installation parameters (i.e., variables that are set for each installation of a UI extension), those have to be set using the Content Management API with a PUT request to https://api.contentful.com/spaces/:space_id/environments/:environment_id/extensions/:extension_id and the body like so:

{
  "extension": {
    "name": "Marketo forms",
    "id": "marketo-forms",
    "srcdoc": "./app.html",
    "fieldTypes": ["Object"],
    "parameters": {
      "installation": [
        {
          "id": "serviceUri",
          "type": "Symbol",
          "name": "Lambda Function URL",
          "required": true
        }
      ]
    }
  }
}

You would also make a similar request if you wanted to add more instance parameters or change any metadata about the instance parameters (name, type, required, options, etc.)

You can easily set the instance parameters by sending a PUT request in Postman. The extensions json with CMA token and also “X-Contentful-Version” for the extension must be passed in order to do so. If you don’t know the version of the extension try doing a GET request and the response will contain version.

Is there any outlook on getting default values in the CMS?

What’s the justification for not including default values for a CMS system again?

1 Like

This discussion is going on for more than 3 years now.
While everyone agrees that this feature is super useful, we are trying to figure out ways to get default values in API response, but we also need the feature in UI to make things easier for content creators.

For my use-case, there are multiple types of fields, not just the Radio button, that need to have default values in them to make it easier for my content creators to create content.

Up!

Almost 4 years since this was raised. Any chance of having this feature considered?