Jump to content

Field Initial Value


Robin S
 Share

Recommended Posts

Field Initial Value

For most field types, allows the definition of an initial value that is automatically set when pages are created.

The initial value can be set in template context if you want a different initial value in different templates.

Example for a "Countries" Page Reference field using AsmSelect:

initial-value-1

Example with explanatory notes in a CKEditor field:

initial-value-2

Differences from "Default value"

The core allows setting a "Default value" for certain field types. The "Initial value" setting added by this module is different from the "Default value" setting in the following ways:

  1. The "Default value" is a setting that applies only to the inputfield, meaning that the value is shown in the inputfield by default but is not stored until you save the page. By contrast, the "Initial value" is automatically saved to the page when the page is first created.
  2. Related to point 1, when a page is created via the API rather than in the ProcessWire admin the "Initial value" is saved to the page but the "Default value" is not.
  3. The "Default value" has no effect when a field is not "required", but the "Initial value" is set for both required and not required fields.
  4. Related to point 3, a user can empty a field that had an "Initial value" applied but a field with a "Default value" set cannot be emptied.
  5. The "Initial value" setting is available for more field types than "Default value".

Supported field types

The following field types are supported, along with any types that extend them:

  • FieldtypeText (includes types that extend it such as Textarea, CKEditor, URL, etc.)
  • FieldtypeDatetime
  • FieldtypeInteger
  • FieldtypeDecimal
  • FieldtypeFloat
  • FieldtypePage (with all core inputfield types)
  • FieldtypeCheckbox
  • FieldtypeOptions (with all core inputfield types)
  • FieldtypeToggle
  • FieldtypeSelector
  • FieldtypeMultiplier (ProField)
  • FieldtypeCombo (ProField, only supported when File and Image subfields are not used)
  • FieldtypeStars (third-party module)

If you want to try field types beyond this you can define additional types in the module config, but your mileage may vary.

Unsupported field types

It's not possible to set an initial value for these field types, along with any types that extend them:

  • FieldtypeFile (and FieldtypeImage)
  • FieldtypeRepeater (includes types that extend it such as Repeater Matrix and Fieldset Page)
  • FieldtypePageTable
  • FieldtypeTable (ProField)

Notes

Seeing as the initial value is defined in the field config it has no idea of the current page - for the purposes of rendering the initial value inputfield the home page is supplied as a dummy page. This probably isn't an issue in most cases but it might have an effect for some Page Reference fields if they use the current page to limit the selectable pages.

 

https://github.com/Toutouwai/FieldInitialValue
https://processwire.com/modules/field-initial-value/

  • Like 12
  • Thanks 3
Link to comment
Share on other sites

  • 2 weeks later...
  • 7 months later...
8 hours ago, ceberlin said:

Why is an initial value mandatory and not optional?

I don't understand. It's not mandatory to set an initial value setting for a field, and if you have chosen to set an initial value it's not mandatory to keep it for any given page in Page Edit - you can clear the initial value.

Link to comment
Share on other sites

Here I have it like this:

  • If a field is mandatory, also the intitial value field is also mandatory (not always intended by me).
  • If a field is not mandatory, the initial value field is also not mandatory.

Bildschirmfoto 66.jpg

  • Like 1
Link to comment
Share on other sites

13 minutes ago, ceberlin said:

Here I have it like this:

  • If a field is mandatory, also the intitial value field is also mandatory (not always intended by me).
  • If a field is not mandatory, the initial value field is also not mandatory.

Ahh, the config inputfield was inheriting those settings from the field, which is unwanted. Should be fixed now in v0.1.1. Thanks for bringing it to my attention.

  • Thanks 1
Link to comment
Share on other sites

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

×
×
  • Create New...