Jump to content

Best approach if I want to set a default value for a field contents?


martinluff
 Share

Recommended Posts

Suppose I want to set a default value for a field - let's say I've a template for 'cars' and I have a text field for colour and 85% of the cars I sell are black; so each time I create a new car page it would make sense to have black as the default value in this field to speed up page creation.

Wonder if it would make sense to have a config for some field types to set default value? Or perhaps there's just another easy way to do this?

Link to comment
Share on other sites

I think there is currently no default value, so until that's added/resolved, I think creating some custom module with page::save() hook is your best bet.

You just hook on save [before/after, doesn't matter] and edit 'default' fields with default value if blank.

Link to comment
Share on other sites

Adam is right that there is no default value yet. I agree it should be there, and it's in the Fieldtype module's interface to support it. But it's not implemented in the core. This is a side effect of this being a new project, and some non-crucial details like this are missing (though, this particular one used to be there). The way I usually handle defaults is from the template side. If something has an empty value, then (depending on the field and situation) I will output a default value. The advantage is that there aren't a lot of repeated default values in the DB. But that's too much of a compromise, so default values will be coming. This is one of those things I had in there for awhile, and then took it out to think about it and revisit it later.

Link to comment
Share on other sites

  • 2 years later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...