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

Discovering distinct colors for this loading dots script

Looking for assistance with a 10 loading dots animation script. I'm trying to customize the color of each dot individually, but when I create separate divs for each dot and control their colors in CSS, it causes issues with the animation. If anyone ...

What is the method for accessing a selector within a foreach loop?

Whenever a user clicks on a date in the jquery datepicker, two ajax calls are triggered. The goal is for the second ajax call to populate the response/data into a paragraph with the class spots within the first ajax call, displaying available spots for th ...

Unwanted gap appears in the image slider

There seems to be a pesky little gap right below my image slider that I just can't seem to get rid of. I was hoping to spruce it up with a box-shadow, but when I tried it out on jsfiddle, it ended up looking pretty awful because of the annoying gap. I ...

Troubles with caching on Amazon S3

Just starting out in web development and I'm working on updating HTML and CSS files stored on Amazon S3. Our website's backend is hosted on Heroku, while the front-end is on Amazon S3. Whenever I make changes to a CSS file, I can immediately see ...

Anime.js: Grid layout causing issues with displaying simple text animations

I'm attempting to create a text animation within a grid layout using the anime.js library, but unfortunately, the animation isn't displaying. The project consists of just one HTML file. The JavaScript code: <script> import anime from &ap ...

Here is a guide on how to develop a PHP function that interacts with a textarea to display text in the specified color by using syntax like [color:red]

Is it possible to code a PHP function that can work alongside a textarea to display text in the specified color by using a syntax like [color:red]? This function operates in a similar manner to Facebook's @[profile_id:0] feature. ...

The height of the image remains constant when its width is decreased, causing it not to resize proportionally

I am facing an issue with displaying images in a div of various resolutions. When I have a wide image with low height, such as 730x90, it does not show properly on mobile devices. The width shrinks but the height remains the same. Below is the code snipp ...

A custom Python script that generates output in CSV format instead of JSON

I am working with a dataset that looks like this: http://www.edsa-project.eu/adzuna/eyJhbGciOiJIUzI1NiJ9.eyJpIjoiMTA2MzEwMTkwIiwicyI6IkRvZnVlWGs1Unp5S2cyUlFOeWdXRmcifQ.v8u2XQwJUVflPipH2A_wg-HMrjYEl2BkL8EMOrRZ5m0,Back End Developer,n/a,Victoria,51.503378, ...

Having trouble with compiling SCSS code

While diving into the world of SCSS, I decided to compile my SCSS into CSS using npm. So I entered npm run compile: sass as defined in my package.json as follows: "scripts": { "compile:sass": "node-sass sass/main.scss css/style ...

AngularJS - displaying a notification when the array length is empty and customizing the visibility to conceal the default action

I've been working on an Angular project where I display a loading circle that disappears once the content is loaded. This circle is simply a CSS class that I call from my HTML only when the page first loads, like this: Actually, the circle consists o ...

Tips for centering a flexbox on a webpage:

<template> <div> <div class="flex justify-center w-full"> <div class="h-px-500 md:w-1/6 bg-orange-200 text-center">1</div> <div class="h-px-500 md:w-1/6 bg-orange-300 text-center">2</div> <div clas ...

What steps should I take to modify my database while utilizing radio buttons in the edit mode?

I am experiencing an issue with the radio button functionality. When creating a new user.jsp, I am able to successfully add the value from the radio button to the database. However, when I attempt to edit the values in the jsp, the changes do not reflect i ...

file_put_contents - store user-defined variables

When I execute this script, it successfully generates the html page as expected. However, I am encountering challenges in incorporating variables, such as the $_GET request. The content is enclosed in speech marks and sent to a new webpage on my site usin ...

I am looking for information on how to properly handle HTTP errors in Axios when utilizing a blob responseType in VueJs

Using the blob responseType with Axios in my VueJS app allows me to download a document from the server. Everything works fine when the response code is 200, but problems arise when there's an HTTP error. I find it challenging to read the status code ...

Retrieve only the initial tag content using jquery

My goal is to extract the "22" from the following code... <div class="left"> <a class="count-link" href="http://url1.com"> <span>22</span> users </a> <a class="count-link" href="http://url2.com"> <span>10</span ...

Error encountered when accessing JSON data from the DBpedia server in JavaScript

Hello everyone and thank you for your help in advance. I have encountered this error: Uncaught SyntaxError: Unexpected identifier on line 65 (the line with the "Var query", which is the third line) and when I click on the Execute button, I get another e ...

Transmit error notification in JSON format

In my application, I have two servlets: the first servlet acts as a client and establishes an HttpURLConnection to invoke the second servlet. My goal is to send a specific error message formatted as a JSON object. Thus, I utilize the sendError method in t ...

If the span id includes PHP data that contains a certain phrase

Hey there, it's my first time posting and I'm in a bit of a bind with this script... Let me give you some background information first I am trying to create a click function for a register button that will check the span id (e.g. $("#username_r ...

What does the HTML and JS code look like when using Next.Js?

Here's an illustration of the desired result: codepen.io/j0be/pen/jWGVvV How can I implement this HTML and JS in Next.js? I am looking to customize this code using TypeScript and SCSS in Next.js. However, I am unsure about how to convert the HTML an ...

What is the best way to make sure the background color of a container stretches across the full width of the screen?

I am currently learning HTML and CSS, and as a practice project, I am working on building a portfolio webpage. In the image provided, there are two containers, and I am facing an issue with the space on the sides when changing the background color. Despite ...