[SOLVED] Default value(s) for reference fields - how to use this functionality?

I have…

I’m submitting a…

  • [ ] Regression (a behavior that stopped working in a new release)
  • [ ] Bug report
  • [ ] Performance issue
  • [x] Documentation issue or request

Current behavior

When creating content that has a references field with a default value specified it is not populated with the default.

Expected behavior

When creating content that has a references field with a default value specified it is populated with the default.

Minimal reproduction of the problem

  • Create a ‘References’ type field
  • Set a ‘Default Value’ to be the content ID of a valid schema
  • Create a new record for the schema and see the ‘References’ field has not been populated with the ‘Default Value’

Environment

App Name: corecms

  • [x] Self hosted with docker
  • [ ] Self hosted with IIS
  • [ ] Self hosted with other version
  • [ ] Cloud version

Version: 6.3.0

Browser:

  • [X] Chrome (desktop)
  • [ ] Chrome (Android)
  • [ ] Chrome (iOS)
  • [ ] Firefox
  • [ ] Safari (desktop)
  • [ ] Safari (iOS)
  • [ ] IE
  • [ ] Edge

Others:
I only thought this might be possible after seeing this other feature request being marked as ‘[IMPLEMENTED]’: [IMPLEMENTED] Default value(s) for reference fields
However after looking through code and commit history around the time that request was worked on I cannot find out how to do it. Tried with every editor and also other field values in case it matched on text. Apologies if I am missing something obvious!

It should work as you describe, but I will have a look, what the issue is.

It works for me:

Hi Sebastian and thanks for your quick response,

Apologies I forgot a critical piece of information; I am trying to default a component schema’s reference field. I just checked and can see that regular schemas with defaulted reference fields are working as expected, but when a field setup the same way is used as part of a ‘Component’ field it does not get defaulted.

I just checked and defaults for other fields like string, number and boolean are also not applied. Is that something you would expect to be supported or is there a reason why it cannot be done? If the latter we can look into using a workaround.

So revised steps to reproduce are as follows:

  1. Create a component type schema
  2. Add a reference type field to that component schema
  3. Default that field to a valid content ID
  4. Create a normal schema
  5. Add a component type field to that schema
  6. Set that field to target the component type schema created in step 1
  7. Create a new record for that schema; the default is not applied.

This sounds like a bug then.

Ah OK, thanks for confirming that and again for your quick response. Will look for an alternative way forward for now.

I have pushed a fix to master.

Excellent news to start my Monday! Looking forward to trying it out.

1 Like

This topic was automatically closed after 2 days. New replies are no longer allowed.