The combination of select2 and jsonform is not functioning properly

I am having trouble rendering multiple select2 with JSON form.

$('#resource-form').jsonForm({
  schema: {
    rest: {
      type: 'object',
        properties: {
          template_id: {
            type: "array",
            items: {
              type: "string",
            }
          }
        }
      }
    }
  },
  form: [
    {
      type: "select",
      key: "rest.template_id[]"
    }
  ]
});

$("select[name='rest.template_id[]']").select2({
  data: data,
  multiple: true
});

The Select2 functionality works very well, but when I submit the form, the backend receives an empty 'template_id' parameter.

{"rest"=>{"template_id"=>[]}}

I believe my schema and form setup may be incorrect. Can someone please assist me?

Answer №1

If you're looking for a quick fix, here's a handy trick for you. This code snippet will convert all select fields into select2 elements.

$("select").select2({
  data: data,
  multiple: true
})

For a more specific implementation, identify the Select field ID provided by jsonform and use it in the following way:

$("@root_something").select2({
  data: data,
  multiple: true
})

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

How can I ensure that "echo" is only displayed once in a foreach loop while also including

Here is the JSON data I have: { "order_id":"#BCB28FB2", "salutation":"Mr", "name":"Testing Data", "cart":[ { "id":13, "name":"tes1", "tre ...

How does the Rx subscribe function maintain its context without the need to explicitly pass it along

Currently, I am utilizing Rx with Angular2 and making use of the Subscribe method. What intrigues me is that the callbacks of the method are able to retain the context of the component (or class) that initiated it without needing any explicit reference pas ...

How to switch the code from using $.ajax() to employing $.getJSON in your script

How can I convert this code from using AJAX to JSON for better efficiency? AJAX $('#movie-list').on('click', '.see-detail', function() { $.ajax({ url: 'http://omdbapi.com', dataType: 'json', d ...

Locate the next element with the same class using jQuery across the entire document

I'm working with the following HTML: <section class="slide current"></section> <section> <div class="slide"></div> <div class="slide"></div> </section> <section class="slide"></section> ...

Retrieve the offspring of offspring and so forth

Currently, my chosen database is MongoDb. I am looking for a solution to retrieve all descendants of children recursively. Let's take the following scenario: A has B & C as children B has D & E as children D has F & G as children Basic ...

A guide on accessing a dynamic object key in array.map()

How can I dynamically return an object key in array.map()? Currently, I am retrieving the maximum value from an array using a specific object key with the following code: Math.max.apply(Math, class.map(function (o) { return o.Students; })); In this code ...

There is no error handling for the errors originating from this location

Having trouble parsing a JSON file in my iOS application: Here is the code snippet causing issues: let jsonData:NSDictionary = try JSONSerialization.jsonObject(with: urlData! as Data, options: JSONSerialization.ReadingOptions.mutableContainers ) as! NSDi ...

Using TypeScript to convert a JSON date string into a Date object

The backend is sending me a JSON data structure that resembles the following: [{ "schedulingId": "7d98a02b-e14f-43e4-a8c9-6763ba6a5e76", "schedulingDateTime": "2019-12-28T14:00:00", "registrationDateTime": "2019-12-24T16:47:34", "doctorVie ...

Try using the slice method to cut a portion of a JSON object

I am trying to chop up a JSON array, but keep encountering the error message below: Object # has no method 'slice' This is my current code snippet: $scope.getPagedDataAsync = function (pageSize, page, searchText) { setTimeout(function ( ...

How do I set the initial state to a specific node in xstate?

I'm currently working on a multi-step form that guides users through selecting services, providing contact information, and entering billing details. I have implemented a progress bar and event emissions to track the user's current step using xst ...

What are the steps to create a JSON file structured in a tree format?

Can you provide instructions on creating a JSON file in the following tree format? root child1 child11 child2 child21 child22 child3 child31 I am looking to generate a sample JSON file that adheres to the ...

Tips for converting response text into HTML code

I am receiving a text response like this <span class='text-4xl'>description1</span> When I display it on the screen: import React,{useContext, useEffect} from 'react'; import blogsContext from '../context/blogsCon ...

How to display text on a new line using HTML and CSS?

How can I properly display formatted text in HTML with a text string from my database? The text should be contained within a <div class="col-xs-12"> and nested inside the div, there should be a <pre> tag. When the text size exceeds the width o ...

The mobile web app on iOS is stuck in a never-ending loop of showing the

My mobile app is built using angular.js, Twitter Bootstrap, and grunt with a .NET back end. After logging in, the loading spinner keeps showing up constantly in the top nav next to the time and battery status. We make server calls at login through a factor ...

Encountering problem when trying to upload several images at once using a single input in CodeIgniter with

I'm attempting to use CodeIgniter and AJAX to upload multiple images using a single input field. Here's the code I have so far: HTML: <input type="file" name="files[]" id="file" multiple /> AJAX: $("#addItems").on("submit",function(e) { ...

Error code 12004 encountered during the execution of a service request

While working on a service call in my JavaScript code that retrieves XML data using XMLHttpRequest, everything runs smoothly in Chrome and Firefox, successfully fetching the data over HTTPS. However, when attempting to execute the same code in IE11, it ret ...

Handling onclick events in Scrapy Splash: A comprehensive guide

I am attempting to extract data from the following website I have managed to receive a response, but I am unsure how to access the inner data of the items below for scraping: It seems that accessing the items requires handling JavaScript and pagination. ...

A guide to displaying the properties of a JSON document

Can someone assist me in extracting only the country data from the information fetched through this API call? Many thanks! import requests import json url = "https://randomuser.me/api/" data = requests.get(url).json() print(data) ...

Guide on making an SVG tooltip using the Menucool JS extension

I am trying to add a simple tooltip to an SVG "map" when the mouse hovers over a rectangle. To create the tooltip, I would like to utilize this specific plugin. Here is how I have connected the SVG to HTML: <object data="map.svg" type="image/svg+xml" ...

What is the correct method for asynchronously loading CSS files in web development?

On a mission to enhance my website's performance, I set out to achieve the perfect score on PageSpeed Insights. Everything was going smoothly until I encountered an issue with CSS delivery. I initially achieved a flawless result by utilizing the prel ...