Converting Umbraco Json to a CSS class named "[]"

I'm currently using Umbraco with the data-type grid layout and I am trying to add custom settings (CSS classes) to each row/cell. The results are somewhat working, but I want to improve it. Here's the user interface:

https://i.stack.imgur.com/iYFSD.png

The "modifier": "{X}" produces varied results and out of the 3 options available, all seemed to work "best".

Here is the JSON snippet:

[
  {
    "label": "Message Box",
    "description": "Message Box",
    "key": "class",
    "view": "checkbox",
    "modifier": "{3}",
    "applyTo": "cell",
    "config": {
      "items": {
        "key1": {
          "value": "value1"
        },
        "key2": {
          "value": "value2"
        },
        "key3": {
          "value": "value3"
        },
        "key4": {
          "value": "value4"
        }
      }
    }
  }
]

However, when I apply these classes to the cells/rows, they end up looking like this:

<div class="["key1", "key2", "key3", "key4"]">

Unfortunately, the HTML cannot interpret these classes correctly due to the square brackets [] and commas. How can I ensure that the classes are applied properly to the elements?

For reference, here is the modified Foundation5 on Pastebin

You can also find Umbraco's checkbox code on Pastebin

Answer №1

Revise this:

    $scope.$watch('selectedItems', function (newVal, oldVal) {
        $scope.model.value = [];
        for (var x = 0; x < $scope.selectedItems.length; x++) {
            if ($scope.selectedItems[x].checked) {
                $scope.model.value.push($scope.selectedItems[x].key);
            }
        }
    }, true);

Transform this:

    $scope.$watch('selectedItems', function (newVal, oldVal) {
        var classList = [];
        for (var x = 0; x < $scope.selectedItems.length; x++) {
            if ($scope.selectedItems[x].checked) {
                classList.push($scope.selectedItems[x].key);
            }
        }
        $scope.model.value = classList.join(' '); // joining class list
    }, true);

Instead of inserting the entire array containing the class list into your interface, consider joining your array elements and separating individual classes with a space.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Position the Crossmark to align with text using CSS styling

How can I properly align a crossmark and a checkmark with the text behind them? The checkmark looks aligned well, but the crossmark appears to be slightly off to the top-right. I'm hesitant to adjust margins and paddings as it may cause issues when th ...

Unable to set the width for a div element within the bootstrap grid layout

When trying to set the width of a div tag to 100% within a bootstrap grid system (col-lg-3), I noticed that the div ends up taking the full width of the browser instead of just 100% of its parent(col-lg-3). .sidebar { color: #fff; f ...

Avoid allowing users to accidentally double click on JavaScript buttons

I am working with two buttons in a Javascript carousel and need to prevent users from double-clicking on the buttons. Below is the code I am using: var onRightArrow = function(e) { if (unitCtr<=unitTotal) { unitCtr++; TweenLite.to(p ...

html displaying dynamic data in a table

As a beginner in coding, I am attempting to create a dynamic table. The first column is working fine with each new cell being added to the top. However, when I try to add columns, they fill from top to bottom instead of mirroring the first column. I want m ...

Trouble with HTTPS request in Android fragment

My app crashes and returns to the main activity whenever I try to use the search function with the Kitsu API in my fragment. I have observed through Logcat that no data is being fetched, but I am unable to determine what is causing the crash.The LogCat r ...

What is the best method for applying classes to a collection of DOM elements with jQuery?

I attempted two different methods of iterating through the arrays, but encountered the same error: addClass is not function First attempt using a for loop: function game(){ var cards = $('.card'); function initialize(){ for ...

Is it possible for a div nested within another div to still occupy space on the page despite being set

<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $("select#choosebook").change(function(){ $(".title").slideDown(" ...

Guide to decoding a list of interface types from JSON in Golang

In my code, there's a package called variables which contains an interface Variable, and two structs that implement the methods in the interface - NumericalVariable and TextualVariable. Here is how they are structured... package variables type Variab ...

Tips on getting rid of the excess margin added by Android WebView printing

We have been attempting to print content from a webview via Google Cloud Print, but no matter what steps we take, the resulting printout always includes an unwanted margin. Is there a solution to eliminate this margin? We have tried: <body style="marg ...

Revealing and concealing adjacent elements within a specified class

In an attempt to create a carousel that functions by hiding and showing images when the next and previous buttons are clicked, I have organized my images in a table and assigned the li elements a class of 'li'. There are four images in total, wit ...

Conceal a child div through the use of AJAX technology

Utilizing AJAX, I am loading pages on my website. Each page consists of two common div elements - the header div and the content div. When navigating from one page to another, I load the content div of the next page into the current page using the followin ...

Is it possible to switch between Jquery and CSS?

Using PHP, I have created a CSS file that enables me to easily adjust the color of various elements. Is there a way for me to regenerate the stylesheet and apply it to the DOM using JQuery? For example: <?php if (isset($_POST['mycolor'])){ $ ...

Tips on creating adaptable images for mobile viewing

My coding conundrum involves the use of two columns - one for an image and the other for a description of that image. However, when viewing my site on mobile devices, the image is cut off at only half its height. Adjusting both columns to col-sm-6 results ...

Retrieving JSON information using JavaScript

I am encountering an issue with the "Ion.RangeSlider" library. I am attempting to dynamically load values via JSON, but I am unable to get the slider to accept the data from the "from" field. It is important that the value is not hardcoded since the user h ...

Allow-Origin-Control, handler.php for emails, and form validation script

I encountered a strange bug recently. There's been some issues with the HTML5 template I downloaded, specifically related to the contact form and MailHandler.php file. Despite having both files in the same directory, when inspecting element in Chrome, ...

Risk Score Generating Form

As I work on a comprehensive form, there are 5 sections for users to mark if they qualify (using checkmarks). The form consists of approximately 50 questions in total. Each section carries different weights/points (e.g., Section 1 is worth 1 point each, ...

React splits the page and interrupts the scroll event listener

For some reason, my webpage has been split by the React.js library. When attempting to scroll down while hovering over the top navigation menu, scrolling becomes impossible. However, scrolling works fine when done on any other part of the screen. I' ...

Is CSS treated differently in a Rails application?

There's something peculiar happening with two sets of identical html and css files that I have. One set is being loaded through Rails' index.html.erb file via a controller, while the other is running through my public folder as a control. The pub ...

SharePoint 2013 on a mobile device does not support scrolling within iframes

Recently, I set up a SharePoint 2013 website with a few iframes. However, when I access the site on my mobile devices (iPad and Android), I am unable to scroll through the entire page by touching within the iframe. I attempted to solve this issue by inclu ...

`Is there a way to utilize Zend 2 http to transmit json data?`

I've been struggling for days to figure this out - I need to send a JSON encoded data set to an API using Zend 2 HTTP, but so far I haven't had any success. Here is what the API manual states: Bulk Create Contacts This command allows you to inse ...