[
{
"label" : "Include gutter?",
"description" : "Enable the row to include a gutter to both sides.",
"key" : "gutter",
"view" : "boolean",
"applyTo" : "row"
}
]
This works fine. However is it possible to set a default value for the checkbox?
I was hoping that I could include a "value" : "1" in the JSON, but that isn't being picked up.
Hi Lee,
I'm interested in almost the same thing. Id like the boolean to have a value "some-class" instead of "1".
Just from your last sentence, how do you switch the value?
I then consume this view with the configuration like the following
{
"label": "Full Width",
"description": "Makes row stretch the full width of the page.",
"key": "class",
"view": "/path/to/view.html",
"prevalues": [
"full-width",
""
]
}
Little hackish with it's use of prevalues, but it works. The first value is the value when it's true, while the second is the value when it's false. Do note that if you have multiple settings connected to a particular key, like "class," you will need to modify the key to make it distinct and then filter that change out in the grid partial. The grid doesn't allow multiple settings to use the same key at the moment unfortunately (see here for details).
As for setting default values, there isn't a nice way to do that from the grid configuration, as settings aren't added to the to the row/cell until they have a value. It is possible to have default values by modifying grid partial, which would be something like the following inside the RenderElementAttributes function.
var attrs = new List<string>();
JObject cfg = contentItem.config;
if (cfg == null || cfg.gutter == null) {
attrs.Add("gutter=\"{desiredValue}\"");
}
Grid: Row config - Boolean prevalue default value
Following the Grid's settings and styling documentation, I have added a checkbox to a row configuration.
This works fine. However is it possible to set a default value for the checkbox?
I was hoping that I could include a
"value" : "1"
in the JSON, but that isn't being picked up.If I can't set the default value, then I'll end up switching the name of the field to "Disable" instead of "Enable".
Thanks,
- Lee
Hi Lee, I'm interested in almost the same thing. Id like the boolean to have a value "some-class" instead of "1". Just from your last sentence, how do you switch the value?
Thanks
Martin.
Hi Martin,
All I meant by 'switch' was that I'd change the label (from "Enable" to "Disable") - hope that makes sense?
I haven't been able to figure out how to change the default value. Still hoping someone has an idea. :-)
Cheers,
- Lee
Hello Any luck setting default values for settings in Grid?
Thanks /Bilal
Hi Bilal,
No, I wasn't able to change the default value... I ended up changing my label/alias from "Enable" to "Disable".
Cheers, Lee
Thanks Lee. I use another CMS with a PageBuilder component similar to Grid.
They use a text box to indicate a gutter. Hence you can check if the value is empty means keep default or remove and if value exists then use it.
/Bilal
I ran into this issue myself and was able to create a workaround.
I created a custom prevalue view with the following markup.
I then consume this view with the configuration like the following
Little hackish with it's use of prevalues, but it works. The first value is the value when it's true, while the second is the value when it's false. Do note that if you have multiple settings connected to a particular key, like "class," you will need to modify the key to make it distinct and then filter that change out in the grid partial. The grid doesn't allow multiple settings to use the same key at the moment unfortunately (see here for details).
As for setting default values, there isn't a nice way to do that from the grid configuration, as settings aren't added to the to the row/cell until they have a value. It is possible to have default values by modifying grid partial, which would be something like the following inside the RenderElementAttributes function.
is working on a reply...