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

How to use the content of a text field as a title for another field in a blueprint

admin

Started by Adrien Goua 5 years ago · 1 replies · 516 views
5 years ago

I would like to use the content of text field as a label for another field. I use a fieldset and I would like that the title of the field is set by the content of a subfield (the page will have six different field set and I want to allow the user to name it so it will give a better overview). Here's my code with an idea of what I'm looking for

YAML
form:
  fields:
    tabs:
      fields:               
        content:
          fields:

            header.fieldset:
              type: fieldset
              title: page.header.titlepart1 //get the content of header.titlepart1 here
              info: part1
              collapsed: true      
              collapsible: true    
              fields:

                header.titlepart1:
                  type: text
                  label: Part 1 title

                header.content1:
                    name: 
                    type: list
                    style: vertical
                    label: Part 1 content
                    fields:
                      .date:
                        type: text
                        label: Date
                      .text:
                        type: markdown
                        label: Texte

Thank you !

5 years ago

@aGooa, The value of a property of a field can be fetched from the server using calls to static php methods. See Using Function Calls (data-*@).

However, while entering the value for field header.titlepart1, its value isn't yet known on the server. After saving the page, its value can be fetched from the saved page using above mentioned technique.

You will have to create the server logic to extract the value from the frontmatter of the page yourself though.

Possibly, you can create a javascript that is added to Admin and gets triggered on change of header.titlepart1 and enters the value into the title of header.fieldset

Suggested topics

Topic Participants Replies Views Activity
Forms & Blueprints · by Ton Haarmans, 5 years ago
13 1140 4 months ago
Forms & Blueprints · by Hugo Oliveira, 5 months ago
0 63 5 months ago
Forms & Blueprints · by Flachy Joe, 6 months ago
9 138 6 months ago
Forms & Blueprints · by Augustus, 7 months ago
7 114 7 months ago
Forms & Blueprints · by Julien, 7 months ago
10 132 7 months ago