Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

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 · 651 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 FrViPofm, 5 days ago
5 100 4 days ago
Forms & Blueprints · by Ton Haarmans, 6 years ago
13 2119 7 months ago
Forms & Blueprints · by Hugo Oliveira, 8 months ago
0 604 8 months ago
Forms & Blueprints · by Flachy Joe, 9 months ago
9 694 9 months ago
Forms & Blueprints · by Augustus, 10 months ago
7 741 10 months ago