Hi All,
I have an "import" button set up on my data table so that values can get pasted in directly from a spreadsheet. Is there a way to prevent submission if one of the values for one of the fields is empty or of wrong data type (e.g. can I set a restriction for a field to be numbers only)?
Here is the javascript I'm using below:
fd.rendered(function() {
var grid = fd.control('CarrierUpdates').widget;
grid.setOptions({toolbar: [
'create',
{
name: 'import',
text: 'Import'
}]
});
$('.k-grid-import').click(function(e){
// get the grid position
var offset = $(this).offset();
// crete a textarea element which will act as a clipboard
var textarea = $('<textarea placeholder="Paste your text here..."></textarea>');
// position the textarea on top of the grid and make it transparent
textarea.css({
position: 'absolute',
top: offset.top,
left: offset.left,
border: '1px solid grey',
width: 200,
height: 100
})
.appendTo('body')
.on('paste', function() {
// handle the paste event
setTimeout(function() {
// the the pasted content
var value = $.trim(textarea.val());
// get the pasted rows - split the text by new line
var rows = value.split('\n');
var data = [];
for (var i = 0; i < rows.length; i++) {
var cells = rows[i].split('\t');
data.push({
Carrier: cells[0],
DeliveryNote: cells[1],
PlannedPickupDate: cells[2],
OTMPUAppointment: cells[3],
CustomerMaster: cells[4],
PlantShortName: cells[5],
Destination: cells[6],
OTMNumber: cells[7],
RisktoMakePUAppointment: cells[8],
IssueReason: cells[9],
NewETADatePickUp: cells[10],
NewETATimePickUp: cells[11],
Comments: cells[12]
});
};
grid.dataSource.data(data);
textarea.remove();
});
})
.on('focusout', function() {
$(this).remove();
});
setTimeout(function() {
textarea.focus();
});
});
});
I appreciate any help in advance! Thank you!