Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 02, 2016 @ 13:14
    Lee Kelleher
    1

    Grid: Row config - Boolean prevalue default value

    Following the Grid's settings and styling documentation, I have added a checkbox to a row configuration.

    [
        {
            "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.

    I've seen some trying various true options on another forum post, but sounds like they were unsuccessful.

    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

  • Martin 278 posts 662 karma points
    Nov 10, 2016 @ 10:19
    Martin
    0

    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.

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Nov 10, 2016 @ 10:38
    Lee Kelleher
    0

    Hi Martin,

    Just from your last sentence, how do you switch the value?

    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

  • Bilal Haidar 144 posts 410 karma points
    Jan 02, 2017 @ 17:03
    Bilal Haidar
    0

    Hello Any luck setting default values for settings in Grid?

    Thanks /Bilal

  • Lee Kelleher 4020 posts 15802 karma points MVP 13x admin c-trib
    Jan 02, 2017 @ 18:11
    Lee Kelleher
    0

    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

  • Bilal Haidar 144 posts 410 karma points
    Jan 02, 2017 @ 19:13
    Bilal Haidar
    0

    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

  • Jesse Andrews 191 posts 716 karma points c-trib
    May 18, 2018 @ 19:51
    Jesse Andrews
    0

    I ran into this issue myself and was able to create a workaround.

    I created a custom prevalue view with the following markup.

    <label ng-controller="Umbraco.PrevalueEditors.BooleanController" for="{{htmlId}}" class="checkbox">
        <input name="boolean" type="checkbox" ng-model="model.value" ng-true-value="{{model.prevalues[0]}}" ng-false-value="{{model.prevalues[1]}}" id="{{htmlId}}" />
        <localize key="general_yes">Yes</localize>
    </label>
    

    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).

  • Jesse Andrews 191 posts 716 karma points c-trib
    May 18, 2018 @ 20:12
    Jesse Andrews
    0

    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}\"");
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft