nestedsortable.js toarray not working - javascript

This is my first use of nestedsortable.js in a custom cms creation with codeigniter, So I use it with Codeigniter php framework.
I have an ordered and nested list(for order pages) and I need to convert this list to array with 'toArray' but it's not working
the error message: uncaught typeError: Cannot call method 'match' of undefined
this is my js code:
<script>
$(document).ready(function(){
$.post('<?=base_url("index.php/admin/pages/order_ajax"); ?>',{},function(data){
$('#orderResult').html(data);
});
$('#save').click(function(){
oSortable = $('.sortable').nestedSortable('toArray');
$.post('<?=base_url("index.php/admin/pages/order_ajax"); ?>',{sortable:oSortable},function(data){
$('#orderResult').html(data);
});
});
});
except that everything is good, so I need your help

I had the same problem. The solution is simple. You need set id for your li elements.
<li id="list_1"> etc...
Because without a set id, element returns "undefined" and it throws an error. Function "match" needs string.

Related

How to filter a GridViewDataComboBoxColumn that has the enable call back property turned on?

I'm using callbacks to populate a GridViewDataComboBoxColumn and other columns based on the value of another GridViewDataComboBoxColumn.
using <ClientSideEvents EndCallback="function(s, e) { populateDefaults(s); }"></ClientSideEvents>This functionality is working, but when i try to filter the ASPxGridView i got this Uncaught TypeError: Cannot read property 'SetValue' of null
How can I skip EndCallback function when the user uses the filter?
I found a solution for my problem, and I want to share it. I tried to call my function when the edit form is showen using if (ASPxGridView1.IsEditing()) {.....} and it worked !

Why isn't the test in my jQuery filter function working as expected?

I used a function in filter to check whether the display mode is block but it's not working.
Here's my code:
$("#wrap_element").find("*").filter(function(){
return this.css("display")==="block";
}).css("background-color","red");
Thanks.
You have a console error that hints at the problem:
Uncaught TypeError: this.css is not a function
You need to use a jQuery object since you're calling a jQuery method on it:
return $(this).css("display")==="block";
// ----^^----^
Demo

Need to pass argument in href method

I am working on a web application to show some data graphically using spring framework. In my code I am trying to call a javascript method from href tag of html. Problem is i can't pass argument to that method.
my html snippet is as below where i call the method.
and javascript method as follow
function getLimitHistory(opcode){
console.log("Getting limit history for opcode: "+opcode);
}
Note that limitData.operatorCode is a thymeleaf variable and it has value 'S47648' that i want to pass as argument to the method. But when press on that href item i am getting some error saying
Uncaught SyntaxError: missing ) after argument list VM382:1
I hope somebody will help me here.
I wonder why nobody in the internet faced this problem before.
try using
<a th:href="javascript:getLimitHistory(${limitData.operatorCode})"
th:text="${limitData.operatorCode}"></a>
Need to use th:* prefix. Once templates are compiled, all th:* tags will be disappeared.
Docs:
https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#script-inlining-javascript-and-dart

Javascript and jQuery conflict on seat chart plugin

I am using the jQuery Seat Chart Plugin in my website.
It's an old website so it uses JavaScript but this plugin is in jQuery so I am getting an error on the following jQuery code
function recalculateTotal(sc) {
var total = 0;
//basically find every selected seat and sum its price
sc.find('selected').each(function () {
total += this.data().price;
});
return total;
}
The error in console I get is Uncaught TypeError: this.data is not a function which I am guessing conflict error with JavaScript and jQuery.
When I use following code
sc.find('selected').each(function () {
total += jQuery(this).data().price;
});
It throws following error Uncaught TypeError: this._each is not a function with 'prototype' javascript.
I have tried to create a new extended function, tried to change the javascript versions but I am not able to solve the error.
jQuery is a Javascript library, it's not a different language so there is no conflict there.
I see you're using jQuery's .each() with sc.find('selected') so the issue must be there:
find('selected') will select elements with selected html tag, which I doubt is what you want. you should use .selected if you're selecting elements with that class. or #selected if you have 1 element with said id. more about .find()
if you're trying to get you get .data() from a jQuery selected element selected you should do it like this this.data("price")
if you're trying to get seatCharts's data() make sure you used .seatCharts({}) on your sc element or you won't have the data() function there

"query function not defined for Select2 undefined error"

Trying to use Select2 and getting this error on multiple item input/text field:
"query function not defined for Select2 undefined error"
Covered in this google group thread
The problem was because of the extra div that was being added by the select2. Select2 had added new div with class "select2-container form-select" to wrap the select created. So the next time i loaded the function, the error was being thrown as select2 was being attached to the div element. I changed my selector...
Prefix select2 css identifier with specific tag name "select":
$('select.form-select').select2();
This error message is too general. One of its other possible sources is that you're trying to call select2() method on already "select2ed" input.
In case you initialize an empty input do this:
$(".yourelement").select2({
data: {
id: "",
text: ""
}
});
Read the first comment below, it explains why and when you should use the code in my answer.
I also had this problem make sure that you don't initialize the select2 twice.
For me this issue boiled down to setting the correct data-ui-select2 attribute:
<input type="text" data-ui-select2="select2Options.projectManagers" placeholder="Project Manager" ng-model="selectedProjectManager">
$scope.projectManagers = {
data: [] //Must have data property
}
$scope.selectedProjectManager = {};
If I take off the data property on $scope.projectManagers I get this error.
This issue boiled down to how I was building my select2 select box. In one javascript file I had...
$(function(){
$(".select2").select2();
});
And in another js file an override...
$(function(){
var employerStateSelector =
$("#registration_employer_state").select2("destroy");
employerStateSelector.select2({
placeholder: 'Select a State...'
});
});
Moving the second override into a window load event resolved the issue.
$( window ).load(function() {
var employerStateSelector =
$("#registration_employer_state").select2("destroy");
employerStateSelector.select2({
placeholder: 'Select a State...'
});
});
This issue blossomed inside a Rails application
I also got the same error when using ajax with a textbox then i solve it by remove class select2 of textbox and setup select2 by id like:
$(function(){
$("#input-select2").select2();
});
It seems that your selector returns an undefined element (Therefore undefined error is returned)
In case the element really exists, you are calling select2 on an input element without supplying anything to select2, where it should fetch the data from. Typically, one calls .select2({data: [{id:"firstid", text:"firsttext"}]).
Also got the same error when using ajax.
If you're using ajax to render forms with select2, the input_html class must be different from those NOT rendered using ajax. Not quite sure why it works this way though.
if (typeof(opts.query) !== "function") {
throw "query function not defined for Select2 " + opts.element.attr("id");
}
This is thrown becase query does not exist in options. Internally there is a check maintained which requires either of the following for parameters
ajax
tags
data
query
So you just need to provide one of these 4 options to select2 and it should work as expected.
I got the same error. I have been using select2-3.5.2
This was my code which had error
$('#carstatus-select').select2().val([1,2])
Below code fixed the issue.
$('#carstatus-select').val([1,2]);
I have a complicated Web App and I couldn't figure out exactly why this error was being thrown. It was causing the JavaScript to abort when thrown.
In select2.js I changed:
if (typeof(opts.query) !== "function") {
throw "query function not defined for Select2 " + opts.element.attr("id");
}
to:
if (typeof(opts.query) !== "function") {
console.error("query function not defined for Select2 " + opts.element.attr("id"));
}
Now everything seems to work properly but it is still logging in error in case I want to try and figure out what exactly in my code is causing the error. But for now this is a good enough fix for me.

Categories