Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Forms & Blueprints

Auto toggle text field with default value

Solved by Marcin View solution

Started by Phillip 4 years ago · 2 replies · 350 views
4 years ago

Hello!
Since a few days I started playing around with Blueprints to override the default behavior of some fields in the admin panel.
I have successfully created a custom text field with a default value.
When I edit a page, the default value of "90" is inserted into the field "Latitude":

Now when I save the page, the value is not written to the page header.
I think the problem is the missing tick in the checkbox next to the text field:

Currently my blueprint file looks like this:

YAML
extends@: item

form:
  fields:
    tabs:
      fields:
        options:
          fields:
            publishing:
              fields:
                header.latitude:
                  type: text
                  toggleable: true 
                  label: Latitude
                  default: 90
                  help: The Latitude of this Blog Item
                  placeholder: "For example: 53.75836740024965"
                  validate:
                    required: false
                    type: number
                    min: -90
                    max: 90

Is there any way to automatically set the tick of this checkbox?

Thanks a lot, Phillip

4 years ago Solution

try other way... remove toggleable: true

and in your header twig check {% if header.latitude is not empty %} - do some stuff

hope this will help

👍 2
4 years ago

Hi,
your way works wonderfully - thank you!

Just for my interest: Can I address the checkbox in a blueprint?

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1135 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 61 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 134 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 108 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 128 7 months ago