TextboxList issue for getting Json array - textboxlist

I am currently having problem in using the jQuery API for
TextboxList
what i want is that to access the selected value in the Json array form, now the documentation suggest to use:
$('#form_tags_input').textboxlist();
but when i use it in the jQuery function on button click to get values using [getValues]
method it said undefined.
here is the javascript:
<script type="text/javascript">
$(function () {
// Standard initialization
var t = new $.TextboxList('#SentTo', { unique: true, plugins: { autocomplete: { minlength: 2, onlyFromValues: true}} });
//t.addEvent('bitBoxAdd', ContactAdded);
//t.addEvent('bitBoxRemove', ContactRemoved);
t.getContainer().addClass('textboxlist-loading');
$.ajax({
url: '/Home/GetContacts',
dataType: 'json',
success: function (r) {
t.plugins['autocomplete'].setValues(r);
t.getContainer().removeClass('textboxlist-loading');
}
});
});
function GetValues() {
var tblist = $('#SentTo').textboxlist();
alert(tblist.getValues());
return false;
}
function ContactAdded(e) {
//alert(e);
//GetValues();
return false;
}
function ContactRemoved(e) {
//alert(e);
}
i am using GetValues() function on button click to getvalues.
A help would be much appreciated.
Thanks.

Try to made TextboxLists "t" variable global
The changed code is:
$(function () {
// Standard initialization
t = new $.TextboxList('#SentTo', { unique: true, plugins: { autocomplete: { minlength: 2, onlyFromValues: true}} });
//t.addEvent('bitBoxAdd', ContactAdded);
//t.addEvent('bitBoxRemove', ContactRemoved);
t.getContainer().addClass('textboxlist-loading');
$.ajax({
url: '/Home/GetContacts',
dataType: 'json',
success: function (r) {
t.plugins['autocomplete'].setValues(r);
t.getContainer().removeClass('textboxlist-loading');
}
});
});
function GetValues() {
alert(t.getValues());
return false;
}

Related

Semantic UI modal and ajax loaded content

I have modified original modal.js script to support ajax content as well, and added a new Behavior called "ajax" here is my piece of code:
ajax: function(callback) {
callback = $.isFunction(callback)
? callback
: function(){}
;
var $content = $(this).find('.content');
$.get("contentData.php", function(data) {
$content.html(data);
});
And I call it like:
$('body').on('click', '.domOdal', function() {
$('.ui.modal')
.modal({
observeChanges: true
}).modal('ajax')
});
The above code works perfect and loads content correclty, but I would like to extended a bit more, so I can include additional info such as custom url, dataType, etc pretty much all the ajax options, and I would like to do that from initialization part like:
$('body').on('click', '.domOdal', function() {
$('.ui.modal')
.modal({
observeChanges: true
}).modal('ajax', {"id":5}, dataType:"json", "url": http://myurl.php" etc...)
});
A bit late but this it what's working for me:
$('body').on('click', '.domOdal', function (e) {
e.preventDefault();
$('.ui.modal')
.modal({
blurring: true,
observeChanges: true,
transition: 'scale',
onVisible: function (callback) {
callback = $.isFunction(callback) ? callback : function () { };
var $content = $(this).find('.content');
$.get("contentData.php", function (data) {
$content.html(data);
});
}
}).modal('show')
});
And in your html where the modl is called:
<div class="ui modal">
<i class="close icon"></i>
<div class="content">
</div>
</div>
How about doing it like this:
$('body').on('click', '.domOdal', function() {
$.ajax({
url: "specs.html",
type: 'POST',
dataType: 'xml',
dataType: 'html'
}).done(function(response) {
console.log(response)
$(response).modal();
});
});

blueimp jquery file upload processalways not called

I've been having problems with blueimp processalways.My code is :
<script>
$(function () {
var uploadButton = $('<button/>').addClass('btn btn-primary').prop('disabled',true).text('Processing...').on('click', function () {
var $this = $(this),data = $this.data();
$this.off('click').text('Abort').on('click', function () {
$this.remove();
data.abort();
});
console.log("data = ",data);
data.submit().always(function () {
$this.remove();
});
});$('#fileupload').fileupload({
dataType: 'json',
singleFileUploads: false,
replaceFileInput : false,
add: function (e, data) {
console.log("#1 fileuploadadd data = ",data);
data.context = $('<div/>').appendTo('#files');
$.each(data.files, function (index, file) {
var node = $('<p/>').append($('<span/>').text(file.name));
if(!index){ node.append('<br>').append(uploadButton.clone(true).data(data));}
node.appendTo(data.context);
console.log("#2 fileuploadadd data = ",data);
});
},processalways: function (e, data) {
console.log("processalways!");
var index = data.index, file = data.files[index],node = $(data.context.children()[index]);
if(file.preview) {
node.prepend('<br>').prepend(file.preview);}
if(file.error) {
node.append('<br>').append($('<span class="text-danger"/>').text(file.error));}
if(index+1 === data.files.length) { data.context.find('button').text('Upload').prop('disabled',!!data.files.error);}
},
I cannot understand why processalways is never triggered. I also tried with always instead of process always but there is no difference.
When I have it like :
}).on('fileuploadadd',function (e,data) {
.......
}).on('fileuploadprocessalways', function (e,data) {
it works normally but I cannot understand why.
Additionally, could someone give me an example of using blueimp's formData??
Thank you in advance
I can't give you an example for formData, but for the events.
According to this answer: https://stackoverflow.com/a/20491423
You have to use always if you overwrite the add function.
This works for me.

typehead of bootstrap only show 8 records

hello can any one guide me in my ajax request its always show me only eight record .
$(this).typeahead({
source: function (query, process) {
jQuery.ajax({
url: url + "/ajax/productdetail",
type: 'GET',
limit: 10,
data: {
cat: $type,
name: query,
form: $form,
setupid: $setupid
},
dataType: 'json',
success: function (response) {
objects = [];
map = {};
$.each(response, function (i, object) {
//debugger;
map[object.name] = object;
objects.push(object.name);
});
process(objects);
}
});
}
});
Just add an option "items" while instantiating the typeahead method. Hope the below sample will help you to understand.
$('input#auto-complete-field').typeahead({
minLength : 0,
items: 9999,
source: function (query, process) {
objects = [];
map = {};
$.ajax({
.......
......
});
}
updater: function(item) {
.............
.............
}
});

retreival of x-axis value on a google chart getselection

I use a column chart. When clicking at one of the rows in the diagram my listener trigger an event:
google.visualization.events.addListener(chart, 'select', renderList);
I am only able to retrieve the number 2456 and not 6. Number 6 is the value of my first column. I have two columns in my table. Can someone please help me with this? I've been struggling for quite some time.
This is the instantiation of the chart:
<script type="text/javascript">
$("select").change(function () {
drawChart();
});
function drawChart() {
var inputData = {
rooms: $("#Rooms").val(), area: $("#Areas").val(), apartmentType: $("#ApartmentType").val(),
queue: $("#Queue").val(), year: $("#Years").val()
}
$.ajax({
url: '#Url.Action("AllocatedApartments", "Statistics")',
dataType: 'json',
data: inputData,
type: 'POST',
success: function (data) {
tdata = new google.visualization.DataTable();
tdata.addColumn('number', 'Antal bostäder');
tdata.addColumn('number', 'Kötid');
$.each(data.GroupedList, function (key, value) {
tdata.addRow([value.QueueTime, value.Count])
});
var options = {
title: 'Förmedlade bostäder',
backgroundColor: "F1F1F1",
colors: ['73a948'],
legend: { "position": "none" },
vAxis: { title: 'Antal förmedlade bostäder', titleTextStyle: { color: 'gray' } },
hAxis: { title: 'Kötidsintervall (antal år)', titleTextStyle: { color: 'gray' } }
};
chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
chart.draw(tdata, options);
google.visualization.events.addListener(chart, 'select', renderList);
}
});
}
</script>
In the function renderList I want to fetch the label of the row selected:
function renderList() {
var selection = chart.getSelection();
var value = tdata.getValue(selection.row, selection.column );
alert(value)
$.ajax({
url: '#Url.Action("RenderApartmentList", "Statistics")',
dataType: 'json',
type: 'POST',
data: inputData,
success: function (data) {
var html = Mustache.to_html(template, data)
$("#myPartialViewContainer").html(html);
},
error: function (xhr) {
alert("Ett fel uppstod, var god försök igen om en liten stund.")
}
});
}
For this part of code
function renderList() {
var selection = chart.getSelection();
var value = tdata.getValue(selection.row, selection.column );
alert(value)
...
you have to receive error in console log:
Uncaught Error: Invalid row index undefined. Should be in the range [0-53].
getSelection() returns an array. So you have to change that to:
function renderList() {
var selection = chart.getSelection();
var value = tdata.getValue(selection[0].row, selection[0].column );
See google docs about Column chart: getSelection() Array of selection elements
And Extended description of getSelection()

Angularjs RESTul Resource Request

I am trying to make the request
....port/trimService/fragments/?fragment_name=:fragmentName
However if I try to make the "?fragment_name" a parameter, it breaks. As I am going to have more requests, my action with change so I cannot leave it in the url portion of the resource.
angular.module(foo).factory('FragmentService', ['$resource',
function ($resource)
{
var FragmentService = $resource('.../fragments/:action:fragmentName',
{},
{
'getFragments':
{
method: 'GET',
isArray: true,
params:
{
fragmentName: "#fragmentName",
action: "?fragment_name="
}
}
});
return FragmentService;
}
]);
As of right now, I have no idea what my URL is actually outputting.
EDIT: I changed my resource as /u/akonsu had mentioned below. I also added my controller as it is still not working correctly.
angular.module(foo).factory('FragmentService', ['$resource',
function ($resource)
{
var FragmentService = $resource('.../fragments/',
{},
{
'getFragments':
{
method: 'GET',
isArray: true,
params:
{
fragmentName: "#fragmentName",
}
}
});
return FragmentService;
}
]);
angular.module(foo).controller('FragmentController', ['$scope', 'FragmentService',
function ($scope, FragmentService)
{
$scope.fragmentQuery = {
fragmentName: 'a',
};
$scope.fragmentQuery.execute = function ()
{
if ($scope.fragmentQuery.fragmentName == '')
{
$scope.fragments = {};
}
else
{
$scope.fragments = FragmentService.getFragments(
{
fragmentName: $scope.fragmentQuery.fragmentName,
});
}
};
$scope.fragmentQuery.execute();
}
]);
Try omitting the query string altogether in the resource URL and just supply your fragmentName as a parameter to the action call. It should add it to the query string if it is not in the list of URL parameters.
$resource(".../port/trimService/fragments/").get({fragmentName: 'blah'})