I have multiple dropzones (upload element) in which preview elements are shown for every file that is added. Every preview has an input number field.
Every dropzone is a form which has a hidden input field with a value in it, this value is the total allowed sum of all input fields inside the dropzone element.
So for example:
Dropzone 1 has total sum of: 10
And two previews with inputs, then for example this is possible:
input1: 10
input2: 0
Or
input1: 5
input2:5
etc
as long as the total is 10. You should not be able to exceed the 10 or when for example input1 has 3 as a value, the second input should not be able to exceed 7 etc.
I tried the following:
const attributeVal = $input;
attributeVal.on("change paste keyup input", function(e) {
let newVal = Math.floor($input.val());
newVal = Math.max(0, newVal);
newVal = Math.min(10, newVal);
const maxValue = parseInt(aantal);
let valueSpent = 0;
$input.not(this).each(function() {
valueSpent += +$input.val();
});
if (newVal + valueSpent > maxValue) {
// Invalid, reset these points to the maximum allowable:
newVal = maxValue - valueSpent;
}
// New value has been validated, put it into the DOM:
$input.val(newVal);
});
attributeVal.on("cut copy paste", function(e) {
e.preventDefault();
});
Where $input is the input field in that current preview and aantal is the total sum. The problem is (in this case aantal = 10) every input field can have 10 (it doesn't exceed) so it is not seeing the values of other inputs.
I tried changing $input.not(this).each(function() { to $input.each(function() { but when I add two images and so there are two input fields, I can only go to 5 in each one. The total is 10 so that is correct but it is not possible to add 9 in one and 1 in the other, only up to 5 in each.
How can I get that result?
I added a jsfiddle here: https://jsfiddle.net/ar2395bw/ (to get the previews you can drag files in the big boxes or click on them and upload some files).
There are a few issues with the code in the JSFiddle (the code posted above is not enough to diagnose the issue).
Not finding all $input
let $preview = $(file.previewElement);
let $input = $preview.find('.fileinput');
Your $preview is connected to each file, so you will only ever find one $input, the one that is being changed.
Incorrect use of .each()
$input.not(this).each(function() {
The function passed to .each() must accept as arguments an index and the value. As it is currently set up, $input will always refer to the same value in every iteration of the loop.
Attempt to compute a total with a sanitised / modified value
newVal = Math.max(0, newVal);
newVal = Math.min(10, newVal);
Here ensure that newVal is in the range 0-10, but then you use the changed value to compute the total newVal + valueSpent > maxValue
Solution
The following code fixes all of these issues.
const attributeVal = $input;
attributeVal.on("change paste keyup input", function (e) {
const maxValue = parseInt(aantal);
let valueSpent = 0;
$preview.closest('.dropzone').find('.fileinput').each(function (index, input) {
valueSpent += +$(input).val();
});
if (valueSpent > maxValue) {
// Invalid, reset these points to the maximum allowable:
$input.val($input.val() - (valueSpent - maxValue));
}
});
attributeVal.on("cut copy paste", function (e) {
e.preventDefault();
});
This works for me on the JSFiddle.
There are multiple issues:
Not every drop zone has aantalinput
aantalinput must be a class not an id let aantal = $el.find('.aantalinput').val();
$input all the time from current drop zone should be like let $input = $('table').find('.fileinput');
let $input = $('table').find('.fileinput'); must be inside attributeVal.on("change paste keyup input", function(e) { and const attributeVal =$preview.find('.fileinput');
let counter = 0;
$('.dropzone').each(function(index, element){
let $el = $(element);
let $maxfiles = $el.attr('maxfiles');
let $inputquantity = $el.find('input').val();
let uploaded_preview = $('.hiddendiv').html();
let aantal = $el.find('.aantalinput').val();
let $thisdropzone = $el;
let total_container = $el.parent().find('.row-total');
$el.dropzone({
paramName: 'postedFile',
addRemoveLinks: true,
dictDefaultMessage: '<i class="fas fa-file-upload uploadicon"></i> <span class="uploadtxt">Upload je bestand(en)</span>',
dictRemoveFile: 'Verwijder',
dictCancelUpload: 'Annuleren',
dictInvalidFileType: 'Dit type bestand is niet toegestaan',
dictCancelUploadConfirmation: 'Weet je zeker dat je het uploaden wilt annuleren?',
dictMaxFilesExceeded: 'Maximale aantal bestanden overschreden',
maxFiles: $maxfiles,
acceptedFiles: '.jpg, .jpeg, .png, .pdf, .tif, .tiff',
thumbnailWidth: '205',
thumbnailHeight: '140',
thumbnailMethod: 'crop',
previewTemplate: uploaded_preview,
processing: function (file) {
},
// File contains dropzone file object, response contains ajax response from php file
error: function (file, response) {
counter++;
console.log('Option ' + counter);
response = '[{"status":"error","filename":"instablok'+counter+'.jpg","filesize":22822,"tmp_name":"\/tmp\/phpI6ov6y","height":172,"width":565,"heightcm":"6'+counter+',07","widthcm":"19'+counter+',93","tifwidth":null,"dpi":"72"}]';
let file_meta = JSON.parse(response);
let $preview = $(file.previewElement);
let $plusbtn = $preview.find('#plusupload');
let $minbtn = $preview.find('#minupload');
const attributeVal =$preview.find('.fileinput');
attributeVal.on("change paste keyup input", function(e) {
let $input = $('table').find('.fileinput');
let newVal = Math.floor(this.value);
newVal = Math.max(0, newVal);
newVal = Math.min(10, newVal);
const maxValue = parseInt(aantal);
let valueSpent = 0;
$input.not(this).each(function() {
valueSpent += parseInt(this.value);
});
if (newVal + valueSpent > maxValue) {
// Invalid, reset these points to the maximum allowable:
newVal = maxValue - valueSpent;
}
// New value has been validated, put it into the DOM:
this.value = newVal;
});
attributeVal.on("cut copy paste", function(e) {
e.preventDefault();
});
if(file_meta[0].status == 'success'){
}else if(file_meta[0].status == 'error'){
$preview.find('.vrijgevenbtn').show();
$preview.find('.foutformaat').show();
}
$preview.find('.bestandnaam').text('Bestandsnaam: ' + file_meta[0].filename);
$preview.find('.resolutie').text('Resolutie: ' + file_meta[0].dpi + ' DPI');
$preview.find('.formaat').text('Formaat: ' + file_meta[0].heightcm + ' x ' + file_meta[0].widthcm + 'cm');
},
})
});
.hiddendiv {
display: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<script type="text/javascript">
// Disable auto discover for all elements:
Dropzone.autoDiscover = false;
</script>
<link rel="stylesheet" href="https://rawgit.com/enyo/dropzone/master/dist/dropzone.css">
<table class="table upload-table">
<tbody>
<tr>
<td class="plantmore-product-thumbnail uploadimg" width="100">
<img src="assets/images/noimg.jpg" alt="">
</td>
<td class="plantmore-product-name" width="200">
<div class="prodinfocheckout">
<a class="prodname" href="">
Monomeer
</a>
<span id="togglespecscheckout" class="prodspecscheckout noselect">
<i class="fas fa-chevron-down"></i> Specificaties
</span>
<div class="togglespecscheckout">
Hoogte : 20cm
<br>
Breedte : 20cm
<br>
uploaden : 1
<br>
Lijmlaag : Wit
<br>
Laminaat : Anti-slip laminaat
<br>
Afwerking : Contoursnijden
<br>
</div>
</div>
</td>
<td class="plantmore-product-quantity" width="190">
<span class="centervertical">
<button class="infotooltip tooltipupload" data-tooltip="Lorem ipsum">
<i class="fas fa-info-circle"></i>
</button>
<span class="amount">
Benodigd formaat:<br>
<span class="benodigd">20 x 20cm</span>
</span>
</span>
</td>
<td class="plantmore-product-quantity" width="185">
<span class="centervertical">
<button class="infotooltip tooltipupload" data-tooltip="Lorem ipsum">
<i class="fas fa-info-circle"></i>
</button>
<span class="amount">Benodigde aantal<br> bestanden: <span class="benodigd">10</span></span>
</span>
</td>
<td class="plantmore-product-quantity">
<span class="centervertical">
<button class="infotooltip tooltipupload" data-tooltip="Lorem ipsum">
<i class="fas fa-info-circle"></i>
</button>
<span class="amount">Bestanden <br>toegewezen: <span class="benodigd">0 / 10</span></span>
</span>
</td>
<td class="plantmore-product-quantity" valign="top">
<button class="uploadbutton btn yellowbtn dz-clickable">Bestand(en) uploaden</button>
</td>
</tr>
<tr class="newrow">
<td colspan="6">
<h6 class="row-total">total: 0 </h6>
<form action="upload/uploaden.php" class="dropzone dropzoneform dz-clickable" maxfiles="10" id="dropzone1">
<input type="hidden" value="Monomeer" name="productnaam">
<input type="hidden" value="Twan" name="klantnaam">
<input type="hidden" value="20" name="hoogte">
<input type="hidden" value="20" name="breedte">
<input class="aantalinput" type="hidden" value="10" name="aantal">
<div class="dz-default dz-message"><span><i class="fas fa-file-upload uploadicon"></i> <span class="uploadtxt">Upload je bestand(en)</span></span></div>
</form>
</td>
</tr>
<tr>
<td class="plantmore-product-thumbnail uploadimg" width="100">
<img src="assets/images/noimg.jpg" alt="">
</td>
<td class="plantmore-product-name" width="200">
<div class="prodinfocheckout">
<a class="prodname" href="">
Monomeer
</a>
<span id="togglespecscheckout" class="prodspecscheckout noselect">
<i class="fas fa-chevron-down"></i> Specificaties
</span>
<div class="togglespecscheckout">
Hoogte : 90cm
<br>
Breedte : 90cm
<br>
uploaden : 1
<br>
Lijmlaag : Wit
<br>
Laminaat : Anti-slip laminaat
<br>
Afwerking : Contoursnijden
<br>
</div>
</div>
</td>
<td class="plantmore-product-quantity" width="190">
<span class="centervertical">
<button class="infotooltip tooltipupload" data-tooltip="Lorem ipsum">
<i class="fas fa-info-circle"></i>
</button>
<span class="amount">
Benodigd formaat:<br>
<span class="benodigd">90 x 90cm</span>
</span>
</span>
</td>
<td class="plantmore-product-quantity" width="185">
<span class="centervertical">
<button class="infotooltip tooltipupload" data-tooltip="Lorem ipsum">
<i class="fas fa-info-circle"></i>
</button>
<span class="amount">Benodigde aantal<br> bestanden: <span class="benodigd">1</span></span>
</span>
</td>
<td class="plantmore-product-quantity">
<span class="centervertical">
<button class="infotooltip tooltipupload" data-tooltip="Lorem ipsum">
<i class="fas fa-info-circle"></i>
</button>
<span class="amount">Bestanden <br>toegewezen: <span class="benodigd">0 / 1</span></span>
</span>
</td>
<td class="plantmore-product-quantity" valign="top">
<button class="uploadbutton btn yellowbtn dz-clickable">Bestand(en) uploaden</button>
</td>
</tr>
<tr class="newrow">
<td colspan="6">
<h6 class="row-total">total: 0 </h6>
<form action="upload/uploaden.php" class="dropzone dropzoneform dz-clickable" maxfiles="1" id="dropzone4">
<input type="hidden" value="Monomeer" name="productnaam">
<input type="hidden" value="Twan" name="klantnaam">
<input type="hidden" value="90" name="hoogte">
<input type="hidden" value="90" name="breedte">
<input class="aantalinput" type="hidden" value="10" name="aantal">
<div class="dz-default dz-message"><span><i class="fas fa-file-upload uploadicon"></i> <span class="uploadtxt">Upload je bestand(en)</span></span></div>
</form>
</td>
</tr>
</tbody>
</table>
<div class="hiddendiv">
<div class="dz-preview dz-file-preview">
<div class="dz-image"><img data-dz-thumbnail /></div>
<div class="dz-details">
<div class="dz-size"><span data-dz-size></span></div>
<div class="dz-filename"><span data-dz-name></span></div>
</div>
<div class="dz-progress"><span class="dz-upload" data-dz-uploadprogress></span></div>
<div class="dz-error-message"><span data-dz-errormessage></span></div>
<span class="infoline">
<span class="infospan bestandnaam">Bestandnaam:</span>
<!-- <i class="fas fa-times-circle afgekeurd"></i> -->
</span>
<span class="infoline">
<span class="infospan resolutie">Resolutie:</span>
<!-- <i class="fas fa-check-circle goedgekeurd"></i> -->
</span>
<span class="infoline">
<span class="infospan formaat">Formaat:</span>
<!-- <i class="fas fa-times-circle afgekeurd"></i> -->
</span>
<div class="foutformaat">
<span>Bestand heeft niet het benodigde formaat.</span>
<span class="uploadinfobox">
<button class="infotooltip tooltipupload" data-tooltip="Lorem ipsum">
<i class="fas fa-info-circle"></i>
</button>
</span>
</div>
<button class="yellowbtn btn vrijgevenbtn" type="button">Bestand vrijgeven</button>
<hr class="uploadline">
<span class="toewijzen">Aantal</span>
<div class="uploadcontent">
<input type="number" value="0" min="0" class="fileinput">
</div>
</div>
</div>
Related
I have table that is populated with items from a database. There is a column to "tick" each item, which calls to the database to change the status of that item to "Valid" - that part works. To save me having to refresh the page though, I would like to then update the text on the page after the ajax call so that it reads "Valid" instead of submitted. What is the correct code to achieve this? Where am I going wrong? Without success, I have also attempted to get the tick to go green once clicked.
<div class="form-group">
<div class="row">
<div class="table-responsive col-md-6">
<h4><i class="glyphicon glyphicon-check"></i> Summary</h4>
<hr />
<table id="stationCount" class="table table-bordered table-hover">
<tr>
<th>ID</th>
<th>Place</th>
<th>Submission Date</th>
<th>Status</th>
<th>Confirm</th>
</tr>
<tr>
<td>
<p id="lblId" class="form-control-static" contenteditable="false">
159
</p>
</td>
<td>
<p id="lblPlaceName" class="form-control-static" contenteditable="false">
Somewhere
</p>
</td>
<td>
<input type="hidden" data-val="true" data-val-required="The SurveyId field is required." id="Items_0__SurveyId" name="Items[0].SurveyId" value="159" />
<p id="lblSubmittedOn" class="form-control-static" contenteditable="false" title="27/03/2018 11:04:47">
27/03/2018
</p>
</td>
<td class="status" id="159">
<p asp-for="Submitted">
Submitted
</p>
</td>
<td>
<a href='#' class='btn btn-default ConfirmLink' style="color: #808080 " data-url='/Controller/ValidateSurvey' data-id="159">
<i class="fa fa-check"></i>
</a>
</td>
</tr>
<tr>
<td>
<p id="lblId" class="form-control-static" contenteditable="false">
3
</p>
</td>
<td>
<p id="lblPlaceName" class="form-control-static" contenteditable="false">
Somewhere else
</p>
</td>
<td>
<input type="hidden" data-val="true" data-val-required="The SurveyId field is required." id="Items_5__SurveyId" name="Items[5].SurveyId" value="3" />
<p id="lblSubmittedOn" class="form-control-static" contenteditable="false" title="21/01/2018 00:00:00">
21/01/2018
</p>
</td>
<td class="status" id="3">
<p asp-for="Submitted">
Expired
</p>
</td>
<td>
<a href='#' class='btn btn-default ConfirmLink' style="color: #808080" data-url='/Controller/ValidateSurvey' data-id="3">
<i class="fa fa-check"></i>
</a>
</td>
</tr>
</table>
</div>
</div>
</div>
$(function() {
//Document.ready//
//link up event handler
$(".ConfirmLink").click(function() {
// Get the id from the link
var recordToConfirm = $(this).attr("data-id");
var postToUrl = $(this).attr("data-url");
$.ajax(postToUrl, {
type: "post",
data: {
"id": recordToConfirm
},
dataType: "json"
}).done(function(data) {
// Successful requests get here
});
if ($(this).css('color') === '#808080') {
$(this).css('color', '#008000');
} else {
$(this).css('color', '#808080');
}
$("#" + recordToConfirm + " td.status").html('Valid');
});
});
I have set up a jsfiddle:
https://jsfiddle.net/a4zhpt7L/4/
To do everything you want, change some things:
Change if ($(this).css('color') === '#808080') to if ($(this).css('color') == 'rgb(128, 128, 128)'), because jQuery returns a rgb code instead of a hex code.
Change $("#" + recordToConfirm + " td.status").html('Valid'); to $("td.status#" + recordToConfirm).html('Valid');, because the td.status was placed incorrectly.
I hope this also fixes your ajax problem.
I'm Trying to compare Values entered in a Textbox (i.e Quantity field ) with Dynamic Value from the backend( AngularJs Service ).
here I need to compare whether Quantity displaying and quantity entering in Textbox matches, else need to display Alert popup.
This is my HTML
<div class="content pageup" ng-app="whApp">
<div id="project-dashboard" class="page-layout simple tabbed">
<!-- content stats here -->
<div class="page-content">
<ul class="nav nav-tabs" id="myTab" role="tablist">
<nav class="breadcrumb">
<a class="breadcrumb-item" ui-sref="processOrders">Orders</a> <span
class="breadcrumb-item active">Raw Materials </span>
</nav>
</ul>
<div class="tab-content">
<div class="tab-pane fade show active" id="home-tab-pane"
role="tabpanel" aria-labelledby="home-tab">
<!-- add user form -->
<div class="widget widget-7 card">
<div class="description bg-purble-custom-100">
<div class="description-text ">
<div class="row">
<div class="col-md-6">
<a href="../assets/pdf/001002135791.pdf" target="_blank">
<h5 class="text-white-500">
<span class="text-white-500 icon-format-page-break"></span>
Order Number :<b> {{processorderProdNumber}} HOSKOTE
PLANT </b>
</h5>
</a>
</div>
<div class="col-md-5 ">
<div class="filter1x">
<a href="../assets/pdf/001002135791.pdf" target="_blank"
data-toggle="tooltip" data-placement="left" title=""
data-original-title="Find the Order PDF"><i
class="text-white-500 s-9 icon-file-pdf"></i> </a>
</div>
</div>
<div class="col-md-1 "></div>
</div>
</div>
</div>
<div class="widget-content p-4">
<!-- the real content inside widger -->
<h5 class="subheading">Material Memo :
{{processOrderDetails[0].productTable.productDescription}}</h5>
<!-- table starts here -->
<!-- the real content inside widger -->
<!-- add user form ends here -->
<table id="sample-data-table" class="table table-striped">
<thead class="thead-dark"
style="background-color: #202528; color: white;">
<tr>
<th class="secondary-text">
<div class="">
<span class="column-title"># </span>
</div>
</th>
<th class="secondary-text">
<div class="">
<span class="column-title">Raw Material No.</span>
</div>
</th>
<th class="secondary-text">
<div class="">
<span class="column-title">Description</span>
</div>
</th>
<th class="secondary-text">
<div class="">
<span class="column-title">Type</span>
</div>
</th>
<th class="secondary-text">
<div class="">
<span class="column-title">Phase</span>
</div>
</th>
<th class="secondary-text">
<div class="">
<span class="column-title">Quantity.</span>
</div>
</th>
<th class="secondary-text">
<div class="">
<span class=""></span>
</div>
</th>
<th class="secondary-text">
<div class="">
<span class="column-title">Action</span>
</div>
</th>
</tr>
</thead>
<tbody ng-repeat="processOrderDetail in processOrderDetails">
<tr>
<th scope="row">{{$index+1}}</th>
<td>{{processOrderDetail.rawmaterialTable.rawmaterialNumber}}</td>
<td>{{processOrderDetail.rawmaterialTable.rawmaterialDescription}}</td>
<td>{{processOrderDetail.type}}</td>
<td>{{processOrderDetail.phase}}</td>
<td>{{processOrderDetail.quantity}}</td>
<td >
<div ng-if="processOrderDetail.rawmaterialTable.rawmaterialNumber != 5947 || processOrderDetail.rawmaterialTable.rawmaterialNumber != 5947">
<button type="button" ng-click="displayResult($event,processOrderDetail.rawmaterialTable.rawmaterialNumber)"
class="btn btn-icon fuse-ripple-ready">
<span class=" text-purble-custom-100 icon-plus-circle"></span>Add
</button>
</div>
</td>
<td><input ng-click="release(processOrderDetail)" onclick="this.style.color='#008000',this.value='RM Released',disabled ='disabled'" class="btn btn-secondary right fuse-ripple-ready"
type="button" value="Release" id="myButton1" />
<!-- <button type="button"
class="btn btn-secondary fuse-ripple-ready"
ng-click="release(processOrderDetail)" onclick="this.style.backgroundcolor = '#4caf50!important'; this.style.color='#000000'; this.disabled=true;" >Release</button>
-->
</td>
</tr>
</tbody>
</table>
<button type="button" data-toggle="modal"
data-target="#doneModal"
class="btn btn-secondary right fuse-ripple-ready" ng-show="showDone"
ng-click="done(processOrderDetails[0].processorderProd.processorderProdNumber)">Done</button>
<script type="text/javascript">
$('#sample-data-table').DataTable({
responsive: true
});
</script>
</div>
</div>
</div>
<script>
function remove(button)
{
//document.getElementById("sample-data-table").deleteRow(-1).innerHTML = '<td>1</td><td>2</td>';
$(button).closest("td").parent().remove();
}
</script>
</div>
</div>
</div>
<!-- content ends here -->
</div>
<script type="text/javascript"
src="../assets/js/apps/dashboard/project.js"></script>
</div>
Here on click of Add+ button ,new row containing fields BatchNumber ,Location and Qty.
i'm intrested to compare Quantity with sum of entered Qty's.
i.e for example if Quantity=600 and Sum(Qty)=600 (100 + 100 + 400) their should be no Warning or Popup , if this doesn't match then Popup should come.
This is My Controller
$scope.displayResult = function($event, rmId) {
console.log("************");
// console.log(button);
console.log(rmId);
var btn = $event.currentTarget;
console.log("************");
$(btn)
.closest("tbody")
.append(
'<tr><td><label for="inputPassword1" class="label-custom">Batch Number</label><input type="text" id="bacthNo" class="bacthNo form-control md-has-value" required ></td><td><label for="inputPassword1" class="label-custom">Location</label> <input type="text" id="location" class="location form-control md-has-value" required ></td> <td ><label for="inputPassword1" class="label-custom">Qty</label> <input type="text" id="qty" class="qty form-control md-has-value" required s></td><td ><label style="display:none;" for="inputPassword1" class="label-custom">Qty</label> <input style="display:none;" type="text" id="rawMaterialId" class="rawMaterialId qty form-control md-has-value" required value="'
+ rmId
+ '"></td><td><button type="button" class="btn btn-danger fuse-ripple-ready" onclick="remove(this);">- remove</button></td></tr> ');
// document.getElementById("appender").
};
$scope.done = function(processorderProdNumber) {
console.log("Calling Status Change");
/** *********** */
console.log("done method called");
var bacthNos = [];
var locations = [];
var qtys = [];
var rawMaterialIds = [];
var data = [];
$("#sample-data-table > tbody > tr").each(
function() {
var eachtr = $(this);
// console.log(eachtr)
var batchNumber = eachtr.find('.bacthNo')
.val();
var location = eachtr.find('.location')
.val();
var quantity = eachtr.find('.qty').val();
var rawMaterialId = eachtr.find(
'.rawMaterialId').val();
if (batchNumber != undefined) {
console.log("batchNo=>" + batchNumber
+ " & location=>" + location
+ " & qty=>" + quantity
+ " & rawMaterialId=>"
+ rawMaterialId);
// alert("batchNo=>"+batchNumber+" &
// location=>"+location+" &
// qty=>"+quantity+" &
// rawMaterialId=>"+rawMaterialId);
bacthNos.push(batchNumber);
locations.push(location);
qtys.push(quantity);
rawMaterialIds.push(rawMaterialId);
}
});
console.log(bacthNos);
console.log(locations);
console.log(qtys);
console.log(rawMaterialIds);
// console.log("sadsadasdsasadsad");
for (var i = 0; i < bacthNos.length; i++) {
data[i] = {};
data[i].batchNumber = bacthNos[i];
data[i].location = locations[i];
data[i].quantity = qtys[i];
data[i].rawMaterialId = rawMaterialIds[i];
}
/** *********** */
console.log(data);
var convertData = [];
for (var i = 0; i < data.length; i++) {
var outerData = data[i];
convertData[i] = {};
// checkContains
if ($scope.checkContains(convertData,
outerData.rawMaterialId)) {
continue;
}
var batchStr = "";
var qtyStr = "";
var locationStr = "";
for (var j = 0; j < data.length; j++) {
var innerData = data[j];
if (outerData.rawMaterialId == innerData.rawMaterialId) {
batchStr += innerData.batchNumber + ",";
locationStr += innerData.location + ",";
qtyStr += innerData.quantity + ",";
}
}
convertData[i].rawMaterialId = outerData.rawMaterialId;
convertData[i].batchNumber = batchStr.substring(0,
batchStr.length - 1);
convertData[i].location = locationStr.substring(0,
locationStr.length - 1);
convertData[i].quantity = qtyStr.substring(0,
qtyStr.length - 1);
}
convertData = convertData.filter(function(x) {
if (JSON.stringify(x) === '{}') { // This will
// check if the
// object is
// empty
return false;
} else
return true;
});
Any corrections and Suggestion welcomed.Thanks in advance.
I know the examples are differing but thats because the js is mixing up however if the vat is show on both the examples and showing the issue i am having....
first example vat is fine, but second your see its showing as 0.20 and i think s not working correctly when over 1000.... anyone know why when over 1000 does not calculate the 20% correctly?
$(document).ready(function() {
// Hide initial values that need updating
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").hide();
// get current delivery rate
$("#get_rate").trigger('click');
// set a timeout and get total and shipping that was generated and add together for nnew total
setTimeout(function() {
// get cart sub-total
var a = $(".cart-total span").text().replace(/\$|£/gi, "");
// get estimated shipping cost
var b = $("#estimated-shipping em").text().replace(/\$|£/, '');
if (b == "FREE") {
b = "0.00"
var isFree = "true";
} else {
b = $("#estimated-shipping em").text().replace(/\$|£/, '');
}
// add together sub-total and estimated shipping to new total
var total = a + b;
total = parseFloat(total.replace(/,/g, ''));
//add the currency with £ (not sure why it was setting $ before)
if (isFree == "true") {
$("#estimated-shipping em").html("FREE");
} else {
$("#estimated-shipping em").html("£" + b);
}
// update with new total with sub-total and added shipping
$('.cart-finalTotal span').html("£" + total.toFixed(2).replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:$|\.))/g, '$1,'));
// show new values
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").show();
}, 2000);
$(".item-quantity input").on("change", function() {
// let initially disable the input to avoid problems
$(".item-quantity input").prop("disabled", true);
// gets auto get rates based on a UK address
$("#get_rate").trigger('click');
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").hide();
setTimeout(function() {
var a = $(".cart-total span").text().replace(/\$|£/gi, "");
// get estimated shipping cost
var b = $("#estimated-shipping em").text().replace(/\$|£/, '');
if (b == "FREE") {
b = "0.00"
var isFree = "true";
} else {
b = $("#estimated-shipping em").text().replace(/\$|£/, '');
}
// add together sub-total and estimated shipping to new total
var total = a + b;
total = parseFloat(total.replace(/,/g, ''));
//add the currency with £ (not sure why it was setting $ before)
if (isFree == "true") {
$("#estimated-shipping em").html("FREE");
} else {
$("#estimated-shipping em").html("£" + b);
}
// update with new total with sub-total and added shipping
$('.cart-finalTotal span').html("£" + total.toFixed(2).replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:$|\.))/g, '$1,'));
// update VAT when input changed
var oldVAT = $(".cart-total span").text().replace(/\$|£/gi, "");
var newVAT = (parseFloat(oldVAT.replace(/(^\d{1,3}|\d{3})(?=(?:\d{3})+(?:$|\.))/g, '$1,')) * 20) / 100;
$(".cart-vat span").html("£" + newVAT.toFixed(2));
// show all new value updates
$("#estimated-shipping em, .cart-finalTotal span, .cart-vat span").show();
// lets enable the quantity input a gain
$(".item-quantity input").prop("disabled", false);
}, 2000);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h1>under 1000</h1>
<form action="/cart" method="POST">
<div class="cart-left">
<table class="cart-items">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Sub-total</th>
<th></th>
</tr>
</thead>
<tbody>
<tr data-variant-id="16285032007">
<td class="item-details">
<a href="/products/avatar-aubergine-dream-1?variant=16285032007" class="item-thumbnail">
<img src="//cdn.shopify.com/s/files/1/1174/5686/products/Avatar-aubergine-dream_011b6ba4-8681-4969-aad2-fcfc7c83121a_small.jpeg?v=1456749751" alt="Avatar - Aubergine Dream - Cover + Bean Filling (UK only)">
</a>
<div class="item-info">
<p class="item-brand" style="width:30px;"></p>
<div class="product-brand" itemprop="brand">
<a href="/collections/vendors?q=Avatar%20Indoor">
<img src="//cdn.shopify.com/s/files/1/0911/4528/t/5/assets/logo-Avatar.jpg" style="width:100px!important">
</a>
</div>
<p></p>
<p class="item-title">Aubergine Dream
</p>
<p class="item-variant">Cover + Bean Filling (UK only)</p>
</div>
</td>
<td class="item-price">
<span class="show-mobile"> PRICE :</span>
<span class="money">£199.00</span>
</td>
<td class="item-quantity">
<input type="number" pattern="[0-9]*" maxlength="4" value="7" data-variant-id="16285032007">
</td>
<td class="item-line-price">
<span class="show-mobile">SUB-TOTAL :</span>
<span class="money" data-currency="GBP">£398.00</span>
</td>
<td class="item-remove">
<i class="icon-cross"></i>
</td>
</tr>
</tbody>
</table>
Continue Shopping
<div class="cart-instructions">
<p>
<label for="cart-note">Add a note to your order</label>
<textarea id="cart-note" rows="4" name="note"></textarea>
</p>
</div>
</div>
<div class="cart-right">
<p class="cart-total">Sub-Total<span class="money" data-currency="GBP">£398.00</span>
</p>
<p class="cart-vat">VAT 20% (included)<span class="money" style="display: block;">£79.60</span>
</p>
<p class="cart-delivery">Delivery (estimated)<span class="money" id="estimated-shipping">+ <em style="display: inline;">£9.00</em></span>
</p>
<p class="cart-finalTotal">Total<span class="money" style="display: block;">£398.01</span>
</p>
<div class="cart-checkout">
<button class="button button-primary button-add-to-cart button-pay-now" type="submit" name="checkout"><span class="icom-lock"></span>Pay Now</button>
<br>
<br>
<div class="additional-checkout-buttons">
<p>Or checkout with</p>
<img id="applePayButton" style="display: none" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="typeof createApplyPayButton === 'function' ? createApplyPayButton(this) : window.addEventListener('applePayReady', (function(){createApplyPayButton(this)}).bind(this))">
<input type="image" name="goto_pp" value="paypal_express" src="https://www.paypalobjects.com/en_US/i/btn/btn_xpressCheckout.gif">
</div>
</div>
</div>
</form>
<h1>over 1000</h1>
<form action="/cart" method="POST">
<div class="cart-left">
<table class="cart-items">
<thead>
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
<th>Sub-total</th>
<th></th>
</tr>
</thead>
<tbody>
<tr data-variant-id="16285032007">
<td class="item-details">
<a href="/products/avatar-aubergine-dream-1?variant=16285032007" class="item-thumbnail">
<img src="//cdn.shopify.com/s/files/1/1174/5686/products/Avatar-aubergine-dream_011b6ba4-8681-4969-aad2-fcfc7c83121a_small.jpeg?v=1456749751" alt="Avatar - Aubergine Dream - Cover + Bean Filling (UK only)">
</a>
<div class="item-info">
<p class="item-brand" style="width:30px;"></p>
<div class="product-brand" itemprop="brand">
<a href="/collections/vendors?q=Avatar%20Indoor">
<img src="//cdn.shopify.com/s/files/1/0911/4528/t/5/assets/logo-Avatar.jpg" style="width:100px!important">
</a>
</div>
<p></p>
<p class="item-title">Aubergine Dream
</p>
<p class="item-variant">Cover + Bean Filling (UK only)</p>
</div>
</td>
<td class="item-price">
<span class="show-mobile"> PRICE :</span>
<span class="money">£199.00</span>
</td>
<td class="item-quantity">
<input type="number" pattern="[0-9]*" maxlength="4" value="7" data-variant-id="16285032007">
</td>
<td class="item-line-price">
<span class="show-mobile">SUB-TOTAL :</span>
<span class="money" data-currency="GBP">£1,194.00</span>
</td>
<td class="item-remove">
<i class="icon-cross"></i>
</td>
</tr>
</tbody>
</table>
Continue Shopping
<div class="cart-instructions">
<p>
<label for="cart-note">Add a note to your order</label>
<textarea id="cart-note" rows="4" name="note"></textarea>
</p>
</div>
</div>
<div class="cart-right">
<p class="cart-total">Sub-Total<span class="money" data-currency="GBP">£1,194.00</span>
</p>
<p class="cart-vat">VAT 20% (included)<span class="money" style="display: block;">£0.20</span>
</p>
<p class="cart-delivery">Delivery (estimated)<span class="money" id="estimated-shipping">+ <em style="display: inline;">FREE</em></span>
</p>
<p class="cart-finalTotal">Total<span class="money" style="display: block;">£1,194.00</span>
</p>
<div class="cart-checkout">
<button class="button button-primary button-add-to-cart button-pay-now" type="submit" name="checkout"><span class="icom-lock"></span>Pay Now</button>
<br>
<br>
<div class="additional-checkout-buttons">
<p>Or checkout with</p>
<img id="applePayButton" style="display: none" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" onload="typeof createApplyPayButton === 'function' ? createApplyPayButton(this) : window.addEventListener('applePayReady', (function(){createApplyPayButton(this)}).bind(this))">
<input type="image" name="goto_pp" value="paypal_express" src="https://www.paypalobjects.com/en_US/i/btn/btn_xpressCheckout.gif">
</div>
</div>
</div>
</form>
This part of my site is with an error and i can't figure out, since i didn't change that in months.
The error is:
Error: [$parse:ueoe] http://errors.angularjs.org/1.4.3/$parse/ueoe?p0=event._id%3FEventController
at Error (native)
at http://localhost:3000/scripts/libs.js:44598:416
at Object.q.consume (http://localhost:3000/scripts/libs.js:44801:157)
at Object.q.ternary (http://localhost:3000/scripts/libs.js:44794:497)
at Object.q.assignment (http://localhost:3000/scripts/libs.js:44794:284)
at Object.q.expression (http://localhost:3000/scripts/libs.js:44794:237)
at Object.q.filterChain (http://localhost:3000/scripts/libs.js:44794:145)
at Object.q.expressionStatement (http://localhost:3000/scripts/libs.js:44794:91)
at Object.q.program (http://localhost:3000/scripts/libs.js:44793:458)
at Object.q.ast (http://localhost:3000/scripts/libs.js:44793:257) <li class="controller__item controller__item--disabled" data-controller-range="[1, 1]" data-event-sidebar-to="false" ng-click="event._id ? EventController.update(event._id, event) : EventController.create(event)">
According to angular.js:
Error: $parse:ueoe
Unexpected End of Expression
Unexpected end of expression: event._id
Description
Occurs when an expression is missing tokens at the end of the expression. For example, forgetting a closing bracket in an expression will trigger this error.
To resolve, learn more about Angular expressions, identify the error and fix the expression's syntax.
The HTML template:
<main class="main">
<div ng-include src="'/admin/navbar/navbar.template.html'"></div>
<div ng-include src="'/admin/breadcrumb/breadcrumb.template.html'"></div>
<section class="events">
<div class="events__container">
<div class="events__row">
<div class="col-md-12">
<div class="events__box">
<div class="events__header">
<h2 class="events__title"> Todos os eventos - </h2>
</div>
<div class="events__body">
<table class="events__table" data-table>
<!-- directive:table-sorter-directive -->
<thead>
<tr>
<th class="events__th events__th--all">
<input type="checkbox" />
</th>
<th class="events__th"> Nome </th>
<th class="events__th"> Data </th>
<th class="events__th events__th--reservations"> Reservas </th>
</tr>
</thead>
<tbody>
<tr class="events__tr" ng-repeat="event in events">
<td class="events__td events__td--checkbox">
<input type="checkbox" data-controller-input ng-click="EventController.retrieveOne(event._id)"/>
</td>
<td class="events__td"> {{ event.name }} </td>
<td class="events__td"> {{ event.date }} </td>
<td class="events__td events__td--reservations"> 50 </td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
<aside class="events__sidebar" data-event-sidebar>
<!-- directive:event-sidebar-directive -->
<form class="events__sidebar-form" method="POST" action="#">
<div class="events__sidebar-group">
<label class="events__sidebar-label" for="event_value"> Valores: </label>
<input class="events__sidebar-input event__sidebar-input--value" type="text" id="event_value" ng-model="event.men"/>
<input class="events__sidebar-input event__sidebar-input--value" type="text" id="event_value" ng-model="event.women"/>
</div>
<div class="events__sidebar-group">
<label class="events__sidebar-label" for="event_name"> Nome do evento: </label>
<input class="events__sidebar-input" type="text" id="event_name" ng-model="event.name"/>
</div>
<div class="events__sidebar-group">
<label class="events__sidebar-label" for="event_hour"> Hora: </label>
<input class="events__sidebar-input" type="text" id="event_hour" ng-model="event.hour"/>
</div>
<div class="events__sidebar-group">
<label class="events__sidebar-label" for="event_point"> Ponto de encontro: </label>
<input class="events__sidebar-input" type="text" id="event_point" ng-model="event.meeting"/>
</div>
<div class="events__sidebar-group">
<label class="events__sidebar-label" for="event_info"> Informações simples: </label>
<input class="events__sidebar-input" type="text" id="event_info" placeholder="1 Hora de Open Bar + 2 horas de loucura"/>
</div>
<div class="events__sidebar-group">
<label class="events__sidebar-label" for="event_hiw"> Como funciona: </label>
<input class="events__sidebar-input" type="text" id="event_hiw" ng-model="event.hiw"/>
</div>
</form>
</aside>
</div>
</section>
<aside class="controller" data-controller>
<!-- directive:controller-directive -->
<!-- directive:controller-action-directive -->
<div class="controller__controller" data-controller-indicator>
<i class="icon icon__cogs"></i>
</div>
<div class="controller__container">
<ul class="controller__list">
<li class="controller__item" data-controller-range="[0]" data-event-sidebar-to="true" ng-click="EventController.clean()">
<i class="icon icon__plus icon__2x"></i>
<span class="controller__legend"> Novo </span>
</li>
<li class="controller__item controller__item--disabled" data-controller-range="[1, 1]" data-event-sidebar-to="true">
<i class="icon icon__pencil icon__2x"></i>
<span class="controller__legend"> Editar </span>
</li>
<li class="controller__item controller__item--disabled" data-controller-range="[1, 1]" data-event-sidebar-to="false" ng-click="event._id ? EventController.update(event._id, event) : EventController.create(event)">
<i class="icon icon__cloud icon__2x"></i>
<span class="controller__legend"> Salvar </span>
</li>
<li class="controller__item controller__item--disabled" data-controller-range="[1]" data-event-sidebar-to="false" ng-click="EventController.delete(event._id)">
<i class="icon icon__trash icon__2x"></i>
<span class="controller__legend"> Deletar </span>
</li>
<li class="controller__item controller__item--email">
<i class="icon icon__search icon__2x"></i>
<span class="controller__legend"> E-mail </span>
</li>
<li class="controller__item controller__item--search">
<i class="icon icon__envelope icon__2x"></i>
<span class="controller__legend"> Pesquisar </span>
</li>
</ul>
</div>
</aside>
</main>
EventController.js:
'use strict';
var EventController = function(scope, EventModel) {
this.scope = scope;
this.EventModel = EventModel;
this.scope.store = [];
this.retrieve();
};
EventController.prototype = {
clean: function() {
this.scope.event = {};
},
create: function(newEvent) {
this.EventModel.Model.insert(newEvent)
.then(function(result) {
});
},
retrieve: function() {
var that = this;
this.EventModel.Model.find()
.then(function(result) {
that.scope.events = result;
});
},
retrieveOne: function(eventId) {
var that = this;
this.EventModel.Model.findOne(eventId)
.then(function(result) {
that.scope.event = result;
});
},
update: function(editedEvent, event) {
this.EventModel.Model.update(editedEvent, event)
.then(function(result) {
});
},
delete: function(eventId) {
this.EventModel.Model.remove(eventId)
.then(function(result) {
});
}
};
angular.module('adminApp').controller('EventController', ['$scope', 'EventModel', EventController]);
I can't figure out what is the problem. Anybody can help?
Thanks.
I believe the error might be cause of the src attribute
ng-include src="'/admin/navbar/navbar.template.html'"
ng-include src="'/admin/breadcrumb/breadcrumb.template.html'"
should be
ng-include="'/admin/navbar/navbar.template.html'"
ng-include="'/admin/breadcrumb/breadcrumb.template.html'"
src should be the attribute only when included as an element <ng-include
But in you case the ng-include is used as an attribute
For more info check the docs ng-include
hide this code in ng-grid.js - it add extra column when group is add.
Moved out of above loops due to if no data initially, but has initial grouping, columns won't be added
if(cols.length > 0) {
for (var z = 0; z < groups.length; z++) {
if (!cols[z].isAggCol && z <= maxDepth) {
cols.push(new ngColumn({
colDef: {
field: '',
width: 25,
sortable: false,
resizable: false,
headerCellTemplate: '<div class="ngAggHeader"></div>',
pinned: grid.config.pinSelectionCheckbox
},
enablePinning: grid.config.enablePinning,
isAggCol: true,
headerRowHeight: grid.config.headerRowHeight
}, $scope, grid, domUtilityService, $templateCache, $utils));
}
}
}
I want after remove input arranged index input name, for example:
After remove input row222[2] others input name as: row000[0] & row111[1] & row333[2]
After remove input row333[3] others input name as: row000[0] & row111[1] & row222[2]
After remove input row111[3] others input name as: row000[0] & row222[1] & row333[2]
etc...
What do i do?
DEMO
My full code:
$(document).on('click', '.RemOve', function(e) {
e.preventDefault();
$(this).closest('.CloSe').remove();
$('.CloSe').each(function(idx) {
var Input = $($('.Change input'), this);
Input.each(function(i) {
var str = $(this).attr('name');
var currentIdx = parseInt(str.match(/\d+/)[0], 10);
$(this).attr('name', str.replace(currentIdx, idx));
})
});
$('.CloSe').each(function(){
$('.namein', this).empty().append($(this).find('input').prop('name'))
})
})
.RemOve{
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="CloSe">
<span class="Change">
<b class="namein">rows[0]</b>
<input type="text" name="rows000[0]"> // rows000[0]
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows[1]</b>
<input type="text" name="rows111[1]"> // rows111[1]
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows[2]</b>
<input type="text" name="rows222[2]"> // rows222[2]
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows[3]</b>
<input type="text" name="rows333[3]"> // rows333[3]
</span>
<span class="RemOve">Remove</span>
</div>
I've updated your code, check out here http://jsfiddle.net/chtvfkt2/1/
And I also commented on some of your codes. If there's a specific reason for using the commented codes, just uncomment and use it.
UPDATE
I'm a bit confused by your question. So I split the answers.
If you want to rename the rest of the elements after getting rid of one of them, take this below.
$(document).on('click', '.RemOve', function(e) {
//I see no point in using preventDefault() here ?
//e.preventDefault();
$(this).closest('.CloSe').remove();
$('.CloSe').each(function(idx, element) {
//var Input = $($('.Change input'), this);
//Improved :: better than using 'this'.
var Input = $($('.Change input'), element);
Input.each(function(i, el) {
//Improved :: No point using parseInt and str.replace ?
//var str = $(this).attr('name');
//var currentIdx = parseInt(str.match(/\d+/)[0], 10);
//$(this).attr('name', str.replace(currentIdx, idx));
var numb = i < 99 ? "rows00" + i : "rows0" + i;
if ( i > 100 ) {
numb = "rows" + i;
}
$(el).attr('name', numb);
})
});
$('.CloSe').each(function(){
$('.namein', this).empty().append($(this).find('input').prop('name'))
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="CloSe">
<span class="Change">
<b class="namein">rows000</b>
<input type="text" name="rows000">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows001</b>
<input type="text" name="rows001">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows002</b>
<input type="text" name="rows002">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows003</b>
<input type="text" name="rows003">
</span>
<span class="RemOve">Remove</span>
</div>
Or if you want to just chop one of them off and expect no changes, take this.
$(document).on('click', '.RemOve', function(e) {
$(this).closest('.CloSe').remove();
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="CloSe">
<span class="Change">
<b class="namein">rows000</b>
<input type="text" name="rows000">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows001</b>
<input type="text" name="rows001">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows002</b>
<input type="text" name="rows002">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows003</b>
<input type="text" name="rows003">
</span>
<span class="RemOve">Remove</span>
</div>
FINAL UPDATE
Just replcaing display text was what you wanted, this code will do.
$(document).on('click', '.RemOve', function(e) {
$(this).closest('.CloSe').remove();
$('.CloSe').each(function(idx, element) {
//Improved :: better than using 'this'.
var Input = $($('.Change input'), element);
Input.each(function(i, el) {
var numb = i < 99 ? "rows00" + i : "rows0" + i;
if ( i > 100 ) {
numb = "rows" + i;
}
$(el).prev().text(numb);
})
});
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="CloSe">
<span class="Change">
<b class="namein">rows000</b>
<input type="text" name="rows000">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows001</b>
<input type="text" name="rows001">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows002</b>
<input type="text" name="rows002">
</span>
<span class="RemOve">Remove</span>
</div>
<div class="CloSe">
<span class="Change">
<b class="namein">rows003</b>
<input type="text" name="rows003">
</span>
<span class="RemOve">Remove</span>
</div>