Thanks a lot @LCD344! I updated the JavaScript file to use non global variables and convert the field names to lowercase.
No problem this is what we got the community for!
anyway, I forked your plugin (for my own use - but of course its open source) - https://github.com/LCD344/kirby-fieldtoggle
diferences
- The style now looks like a switch.
- Itâs based on a checkbox and not togglefield (because I had the switch already done for the checkbox
- Itâs registered through the plugins directory and not fields (personal preference - trying to keep all non original kirby files in the same place)
- Itâs installable using the kirby cli.
Fieldtoggle v2
The Fieldtoggle field just got a lot more powerful. You can now define as many options as you want. Previously you could only use the âYes/Noâ and âTrue/Falseâ options. This makes it possible to do something like that:
https://github.com/medienbaecker/kirby-fieldtoggle/raw/master/structure.gif
Since the syntax had to change obviously, I updated the original post, too.
TL;DR: You now add the options in show
or hide
and list the affected fields.
I will probably try it out in the future. Until then I have a few questions about it.
- What happends to the fields that are not shown, are they still saved to the content text file?
- Is it possible to have ânestingâ hidden parts? Letâs say I want to add a category choice inside a category choice.
- Is it possible to use checkboxes, like match two of them to show the section? or match a specific checkbox.
- Is it possible to have an input text field like match while type feature?
I guess most of the above does not work with the current version but your field seems still very powerful.
Feel free to add what you want from the list as issues to your repo if you like any of the ideas.
-
The hidden fields are still there, just not visible. They are also required, since you canât overwrite the validation.
-
Nesting is possible, I just pushed the necessary commit for that.
Overall itâs important to do something with the value of the fieldtoggle field. It is a normal radio button after all. So in your template youâd still need a condition to check what option was selected. That way itâs not important what the hidden fields store. -
After I wanted to switch from the toggle field, I initially used the checkbox. Fo my use cases this just made it way more complicated. What do you want to use it for?
-
I see the appeal of an instant filter, but I think that would be an entirely different field.
Hi,
Iâm new to Kirby and think I will need this fieldtoggle plugin for a project. In the install docs it mentions to add everything to the âsite/fieldsâ folder. The thing is, Iâm using the Kirby starterkit and it does not have a fields folder⌠Does the plugin require something to be installed that is not in the starter kit or are the install docs incorrect and should I put it in the site/plugins folder?
Regards,
Chantal
Simply create a site/fields
folder, if it doesnât already exists.
Thank you flokosiol!
Hi, is there a way to set a default value?
Yes, you can simply set default:
to whatever option should be selected by default.
For example:
label: Link page
type: fieldtoggle
options:
nolink: No link
internal: Internal link
external: External link
child: First child page
default: external
show:
external: extlink
internal: intlink
hide:
nolink: intlink extlink
external: intlink
internal: extlink
child: intlink extlink
This would set the option external
as default and make the field extlink
visible by default. Remember to remove any existing content in the content files to simulate a newly created page and test the default value.
Note that when you have âyes/noâ options, you have to wrap the default option in quotes:
imagetoggle:
label: Show image?
type: fieldtoggle
default: "no"
options:
yes: "Yes"
no: "No"
show:
yes: imagefield
hide:
no: imagefield
imagefield:
label: Image
type: image
When I copy paste your code it works great⌠I wasnât sure if default
should work, I didnât found it in examples and it didnât work with my values (I tried before). But after I started from scratch it is now OK, so there was something wrong with my blueprint, maybe just a stupid typo⌠Thanks a lot!
Just great, really appreciated!