I am creating the datatables in bootstrap modal and it is working fine for the first time modal opening, but when the modal is reopened, the datatable functions are not working.
$("#unitTypePopupModal .modal-body").empty();
var html = '<div class="container-fluid col-md-12">';
html += '<div class="row">';
html += '<div class="col-xs-10 col-xs-offset-1 col-sm-10 col-sm-offset-1 col-md-10 col-md-offset-1 col-lg-10 col-lg-offset-1">';
html += '<div class="panel panel-default">';
html += '<div class="panel-body">';
html += '<div class="text-center">';
html += '<img src="Images/add-circle.png" class="login" height="70" />';
html += '<h2 class="text-center">Units</h2>';
html += '<div class="panel-body">';
html += '<form id="unitTypePopupForm" name="unitTypePopupForm" role="form" class="form form-horizontal" method="post">';
//html += '<fieldset>';
html += '<div class="form-group">';
html += '<div id="table-container" style="padding:1%;">';
//if (UnitTypeData.length > 0) {
html += '<div class="table-responsive">';
html += '<table id="unitTypesList" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">';
html += '<thead>';
html += '<tr>';
html += '<th>' + '#' + '</th>';
html += '<th>' + 'UnitType Guid' + '</th>';
html += '<th>' + 'UnitType Name' + '</th>';
html += '<th>' + 'Unit List' + '</th>';
html += '<th>' + 'Operation' + '</th>';
html += '</tr>';
html += '</thead>';
html += '<tbody>';
for (var i = 0; i < UnitTypeData.length; i++) {
html += '<tr>';
html += '<td>' + '' + '</td>';
html += '<td>' + UnitTypeData[i].UnitTypeGuid + '</td>';
html += '<td>' + UnitTypeData[i].UnitTypeName + '</td>';
html += '<td>' + 'Unit' + '</td>';
html += '<td>' + '<i class="ui-tooltip fa fa-file-text-o" style="font-size: 22px;" data-original-title="View" title="View"></i>' + ' ' + '<i class="ui-tooltip fa fa-pencil-square-o" style="font-size: 22px;" data-original-title="Edit" title="Edit"></i>' + ' ' + '<i class="ui-tooltip fa fa-trash-o" style="font-size: 22px;" data-original-title="Delete" title="Delete"></i>' + '</td>';
html += '</tr>';
}
html += '</tbody>';
html += '</table>';
html += '</div>';
//} else {
// html += '<p>There is no Unit Type available to be displayed.</p>';
// }
html += '</div>';
html += '</div>';
//html += '</fieldset>';
html += '</form><!--/end form-->';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
$("#unitTypePopupModal .modal-body").append(html);
$('#unitTypePopupModal').modal('show');
$("#unitTypePopupModal").on('show.bs.modal', function () {
$("#unitTypePopupModal .modal-body").empty();
//bootbox.alert(html);
});
$("#unitTypePopupModal").on('hiddden.bs.modal', function () {
//$("#unitTypePopupModal .modal-body").empty();
$(this).data('bs.modal', null);
});
unitTypeTableRelatedFunctions();
$('#unitTypePopupForm').validate({ // initialize plugin
ignore: ":not(:visible)",
rules: {
unitTypeName: {
required: true,
noSpace: true
}
},
messages: {
unitTypeName: {
required: "Please Enter the UnitType Name.",
noSpace: "UnitType Name cannot be empty."
}
},
//errorPlacement: function (error, element) {
// switch (element.attr("name")) {
// case "dpProgressMonth":
// error.insertAfter($("#dpProgressMonth"));
// break;
// default:
// //nothing
// }
//}
});
The following function is called
unitTypeTableRelatedFunctions = function () {
var unitTypeEditing = null;
var table = $('#unitTypesList').DataTable({
responsive: true,
pagingType: "full_numbers",
searchHighlight: true,
stateSave: true,
destroy: true,
//orderable: false,
columnDefs: [
{
targets: [0],
orderable: false,
searchable: false
},
{
className: 'never',//className:'hidden',
targets: [1],
visible: false,
orderable: false,
searchable: false
},
{
targets: [2],
orderable: true
},
{
targets: [3],
orderable: false
},
{
targets: [4],
orderable: false,
searchable: false,
//defaultContent: '<a class="viewWorkItemSubHeadBtn" onclick="editBtnClicked(this);"><i class="ui-tooltip fa fa-file-text-o" style="font-size: 22px;" data-original-title="View"></i></a> <a class="editWorkItemSubHeadBtn"><i class="ui-tooltip fa fa-pencil" style="font-size: 22px;" data-original-title="Edit"></i></a> <a class="deleteWorkItemSubHeadBtn"><i class="ui-tooltip fa fa-trash-o" style="font-size: 22px;" data-original-title="Delete"></i></a>'
}
],
order: [[2, 'desc']],
language: {
//"lengthMenu": "Display _MENU_ records per page",
lengthMenu: 'Display <select>' +
'<option value="5">5</option>' +
'<option value="10">10</option>' +
'<option value="15">15</option>' +
'<option value="20">20</option>' +
'<option value="25">25</option>' +
'<option value="30">30</option>' +
'<option value="35">35</option>' +
'<option value="40">40</option>' +
'<option value="45">45</option>' +
'<option value="50">50</option>' +
'<option value="100">100</option>' +
'<option value="-1">All</option>' +
'</select> records per page',
zeroRecords: "Nothing found - sorry",
info: "Showing page _PAGE_ of _PAGES_",
infoEmpty: "No records available",
infoFiltered: "(filtered from _MAX_ total records)"
},
pageLength: 5,
//select: {
// style: 'os',
// blurable: true
//},
dom: '<"top"<"pull-left"B><f>>rt<"bottom"i<"pull-left"l><p>><"clear">',
//dom: '<lf<t>ip>',
//dom: '<"wrapper"flipt>',
//dom: '<"top"i>rt<"bottom"flp><"clear">',
buttons: [
{
text: '+ Create New UnitType',
className: 'btn-success addNewUnitTypeBtn',
action: function (e, dt, node, config) {
e.preventDefault();
addNewUnitType();
}
}
]
});
table.on('order.dt search.dt', function () {
table.column(0, { search: 'applied', order: 'applied' }).nodes().each(function (cell, i) {
cell.innerHTML = i + 1;
});
}).draw();
$('#unitTypePopupModal').on('click', '#unitTypesList a.editUnitTypeBtn', function (e) {
e.preventDefault();
/* Get the row as a parent of the link that was clicked on */
var selectedRow = $(this).parents('tr')[0];
//var selectedRowIndex = table.row($(this).parents('tr')).index();
if (unitTypeEditing !== null && unitTypeEditing != selectedRow) {
/* A different row is being edited - the edit should be cancelled and this row edited */
restoreUnitTypeRowData(table, unitTypeEditing);
editUnitTypeRow(table, selectedRow);
unitTypeEditing = selectedRow;
addUnitTypeBtn.enable();
$('#unitTypePopupModal input#unitTypeName').focus();
}
//else if (nEditing == selectedRow && this.innerHTML == "Save") {
// /* This row is being edited and should be saved */
// saveRow(oTable, nEditing);
// nEditing = null;
// createBtnClicked = 0;
//}
else {
/* No row currently being edited */
editUnitTypeRow(table, selectedRow);
unitTypeEditing = selectedRow;
addUnitTypeBtn.enable();
$('#unitTypePopupModal input#unitTypeName').focus();
}
});
When edit button is clicked, the click event is fired and the following function is called:
editUnitTypeRow(table, selectedRow)
the function body is:
editUnitTypeRow = function (table, selectedRow) {
var selectedRowData = table.row(selectedRow).data();
var availableTds = $('>td', selectedRow);
availableTds[1].innerHTML = '<input type="text" id="unitTypeName" name="unitTypeName" placeholder="UnitType Name" class="form-control text-capitalize" value="' + selectedRowData[2] + '">';//UnitType
availableTds[2].innerHTML = '';
availableTds[3].innerHTML = '<i class="ui-tooltip fa fa-floppy-o" style="font-size: 22px;" data-original-title="Save" title="Save"></i>' + ' ' + '<i class="ui-tooltip fa fa-times-circle-o" style="font-size: 22px;" data-original-title="Cancel" title="Cancel"></i>'
}
In this function the table row data is not extracted properly.
I am getting the data when the modal is opened for the first time after page reload but if i open the modal second time the table.row() function is not fetching the row data, but the data is present in the row.
The html code is as follows:
<div id="unitTypePopupModal" class="modal fade" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg" style="overflow-y:initial !important;">
<div class="modal-content">
<div class="modal-header" style="display:none"></div>
<%--<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h1 class="text-center">What's My Password?</h1>
</div>--%>
<div class="modal-body" style="max-height:calc(100vh - 200px); overflow-y: auto;">
</div>
<div class="modal-footer">
<div class="col-md-12">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
</div>
</div>
</div>
The clicks in popup modal works initially after page load but do not work after we re-open the popup modal.
Since you are dinamically adding html content, you need to delegate events in a different way
Code like this will execute only if object #selector is present on page at load time
$('#selector').on('click', function(){...etc...});
If you want to delegate event to dinamically added elements, you have to do like this:
$('#container').on('click', '#selector', function(){...etc...});
Where #container exist in DOM since page load. If you want to be 100% sure not to do mistake, just use $(document.body).on(...), but it will slow down a bit your code since the body is full of elements
EDIT after fiddle #12: I'm sorry but your code is way too crowded to easily find a solution. I tried to log some data and I see that when you close and reopen the modal, the event is triggered twice both when you click "Edit" and "Cancel" (I guess other buttons behave the same), so it is actually working correctly, but the secont time it is called, the unitTypeEditing is empty, that's why the input field isn't hiding..
I suggest you to switch to x-editable plugin, this should avoid any problem with restoring previous data and it will result in much less code to write.
Related
Having a Datatable as below:
"Wifi Code" shows the wifi code value, and if the user has provided an email/phone, a respective button is added also to send email/Sms.
I'm trying to display "Wifi Code" in one line, with no wrap.
The table definition:
<table id="visitorsTable" class="display compact responsive nowrap" style="width: 100%">
The ColumnDefs:
columnDefs: [
{
targets: [10], // Wifi Code
className: "noWrapTd", // white-space: nowrap;
render: function(wifiCode, b, data, d) {
// wifi exists
if (wifiCode) {
var content = `<span class="mx-2">${wifiCode}</span>`;
if (data.Email && data.PhoneNumber) {
content +=
'<div>' +
'<button type="button" class="btnResendByMail mx-1">Email <i class="fas fa-envelope"></i></button>' +
'<button class="btnResendBySms">Sms <i class="fas fa-sms"></i></button>' +
'</div>';
return content;
} else {
if (data.Email) {
content +=
'<button class="btnResendByMail">Email <i class="fas fa-envelope"></i></button>';
}
if (data.PhoneNumber) {
content +=
'<button class="btnResendBySms">SMS <i class="fas fa-sms"></i></button>';
}
}
return content;
} else { // wifi does not exists
return '<button class="btnGenerate">Generate <i class="fas fa-wifi"></i></button>';
}
}
}
As you can already see, I have added the "nowrap" class to the table definition.
I've also tried to set a class "className: "noWrapTd", still not good.
Any other idea ?
Modified code:
columnDefs: [
{
targets: [10], // Wifi Code
className: "no-wrap",
width: "200px",
render: function(wifiCode, b, data, d) {
// wifi exists
if (wifiCode) {
var content = "<span class="mx-2">${wifiCode}</span>";
if (data.Email && data.PhoneNumber) {
content +=
'<div class="d-inline">' +
'<button type="button" class="btnResendByMail d-inline mx-1">Email <i class="fas fa-envelope"></i></button>' +
'<button class="btnResendBySms d-inline">Sms <i class="fas fa-sms"></i></button>' +
'</div>';
return content;
} else {
if (data.Email) {
content +=
'<button class="btnResendByMail d-inline">Email <i class="fas fa-envelope"></i></button>';
}
if (data.PhoneNumber) {
content +=
'<button class="btnResendBySms d-inline">Sms <i class="fas fa-sms"></i></button>';
}
}
return content;
} else { // wifi does not exists
return '<button class="btnGenerate d-inline">Generate <i class="fas fa-wifi"></i></button>';
}
}
}
]
First of all I removed the nowrap class from table definition:
<table id="visitorsTable" class="display compact responsive" style="width: 100%">
And the columnDefs:
className: "no-wrap", // Datatables no-wrap class
width: "200px", // Fixed width
Applied d-inline class for the buttons and the div containing the buttons
i am strting to play with Vue and i was wondering how i can update only the current edited text input value instead of updating all instances of it? I know it must be about the v-model , but i am a bit lost here.
Here is my code for the component :
Vue.component('app-list', {
template: '<section id="app-item-field" class="columns is-multiline">' +
' <div class="column is-2" v-for="(list, index) in lists" >' +
' <h2>{{list.title}}</h2>' +
' <div class="field has-addons">' +
' <input class="input is-small is-info" type="text" v-model="inputVal" placeholder="Nom de l\'item à ajouter">' +
' <a class="button is-info is-small" :disabled="initValueIsSet === false" #click="addListItem(index)">Ajouter</a>' +
' </div>' +
' <app-list-items :items="list.items"></app-list-items>' +
' </div>' +
' </section>',
props: ['lists'],
data: function () {
return {
inputVal: null
}
},
computed: {
initValueIsSet: function () {
if (this.inputVal === null) {
return false;
} else {
return this.inputVal.length > 0;
}
}
},
methods: {
addListItem: function (index) {
if (this.initValueIsSet) {
this.$emit('new-list-item', index, this.inputVal, "http://www.google.ca");
this.inputVal = "";
}
}
}
});
Thank you in advance!
The simplest solution is to turn inputVal into an array:
data: function () {
return {
inputVal: []
}
},
And use index from v-for to access it in the v-model. Template:
<input class="input is-small is-info" type="text" v-model="inputVal[index]" placeholder="Nom de l\'item à ajouter">'
Also update the methods.
Demo:
Vue.component('app-list-items', {
template: '<span></span>'
});
Vue.component('app-list', {
template: '<section id="app-item-field" class="columns is-multiline">' +
' <div class="column is-2" v-for="(list, index) in lists" >' +
' <h2>{{list.title}}</h2>' +
' <div class="field has-addons">' +
' <input class="input is-small is-info" type="text" v-model="inputVal[index]" placeholder="Nom de l\'item à ajouter"> {{ inputVal[index] }}' +
' <a class="button is-info is-small" :disabled="initValueIsSet(index) === false" #click="addListItem(index)">Ajouter</a>' +
' </div>' +
' <app-list-items :items="list.items"></app-list-items>' +
' </div>' +
' </section>',
props: ['lists'],
data: function () {
return {
inputVal: []
}
},
methods: {
initValueIsSet: function (index) {
if (this.inputVal[index] === null || this.inputVal[index] === undefined) {
return false;
} else {
return this.inputVal[index].length > 0;
}
},
addListItem: function (index) {
if (this.initValueIsSet(index)) {
this.$emit('new-list-item', index, this.inputVal[index], "http://www.google.ca");
Vue.set(this.inputVal, index, ""); // https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats
}
}
}
});
new Vue({
el: '#app',
data: {
lists: [{title: 'ana', items: []}, {title: 'bob', items: []}]
}
})
<script src="https://unpkg.com/vue"></script>
<div id="app">
<app-list :lists="lists"></app-list>
</div>
Since inputVal is now an array, the computed initValueIsSet is now parameterized by the index. As computeds don't take arguments, we turned it into a method.
HTML code:
<div class="col-sm-9">
<input name="NewCardOrAccountNumber" class="form-control ui-autocomplete-input" id="NewCardOrAccountNumber" type="text" value="" autocomplete="off">
<span class="ui-helper-hidden-accessible" role="status" aria-live="polite"></span>
</div>
<div class="unvisible" id="clientInfoNew">
<div class="form-group">
<label class="col-sm-3 control-label">FIRST NAME</label>
<div class="col-sm-9" id="FnameNew"></div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">LAST NAME</label>
<div class="col-sm-9" id="LnameNew"></div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">BIRTH DATE</label>
<div class="col-sm-9" id="BirthDateNew"></div>
</div>
Watin code:
[TestMethod]
[TestCategory("Rimi Change card page")]
public void Rimi_4444_Change_Card_and_Assert()
{
//Web Address
using (IE ie = new IE(this.Rimi))
{
//IE ie = new IE(RimiChangeCard);
ie.BringToFront();
ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Maximize);
ie.TextField(Find.ById("NewCardOrAccountNumber")).TypeText("9440385200600000020");
If I write card number from keyboard, the invisible class appear, and you can see FIRST NAME, LAST NAME and so on. But if I do this with watin, it does not appear, and you only see card number which you input. Its like hidden fields of information. I do not know how to make that I could see this fields when I input card number.
There would be a JavaScript function, which gets executed when you manually enter the data in the text field.Go through the Java Script functions on the same page which refer to that element using it's ID NewCardOrAccountNumber.
Refer to this link for sample application. Where msg_to is element, and has a KeyUp event associated. When that filed gets a , value, there is a div section inside which a `Subject' field is shown.
Similarly, after executing the TypeText, try to trigger related event mentioned in the Java Script event using Java script execution.
EDIT: I see that the javascript functions gets executed after bulr event is fired. This means the textbox field should loose the focus. Try the below options.
// 1. Try focusing out of control.
ie.TextField(Find.ById("NewCardOrAccountNumber")).TypeText("9440385200600000020");
ie.TextField(Find.ById("OldCardOrAccountNumber")).Click();
ie.WaitForComplete();
// 2. Try Using Send Keys method to tab out.
ie.TextField(Find.ById("NewCardOrAccountNumber")).TypeText("9440385200600000020");
System.Windows.Forms.SendKeys.SnedWait("{TAB}"); // Need to add System.Windows.Forms reference to the project.
I put image on the internet, so click on this link Image and you will see on first image how look page, second picture - what have to happen when you input card number (from keyboard), third - what happen when card namuber is input from watin (does not appear information about card).
HTML code:
<div class="ibox-content">
<br>
<div class="form-horizontal">
<div class="row">
<div class="col-md-5">
<div class="form-group">
<label class="col-sm-3 control-label">NEW CARD</label>
<input name="NewCardId" id="NewCardId" type="hidden" value="0" data-val-required="The NewCardId field is required." data-val-number="The field NewCardId must be a number." data-val="true">
<div class="col-sm-9"><span class="ui-helper-hidden-accessible" role="status" aria-live="polite"></span><input name="NewCardOrAccountNumber" class="form-control ui-autocomplete-input" id="NewCardOrAccountNumber" type="text" value="" autocomplete="off"></div>
</div>
<div class="unvisible" id="clientInfoNew">
<div class="form-group">
<label class="col-sm-3 control-label">FIRST NAME</label>
I maybe find what you looking for Sham, but I do not know how to use it :
<script type="text/javascript">
$(document).ready(function() {
var NewCardId = "#NewCardId";
var OldCardId = "#OldCardId";
var NewCardNumber = "#NewCardOrAccountNumber";
var OldCardNumber = "#OldCardOrAccountNumber";
$(NewCardNumber).autocomplete(
{
source: function(request, response) {
$.ajax({
url: '/LoyaltyWebApplication/Suggestion/GetCardSuggestions',
dataType: "json",
data: {
str: $(NewCardNumber).val()
},
success: function(data) {
response($.map(data, function(item) {
var label = "";
if (item.Fname != null) label += item.Fname;
if (item.Lname != null) label += " " + item.Lname;
if (label.trim() != '') label = " (" + label.trim() + ")";
return {
value: item.CardNumber,
label: item.CardNumber + label
}
}));
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
},
select: function(event, ui) {
getCardDetails($(NewCardNumber), $(NewCardId), 'newCardSegments', true);
$("#newCardSegments").hide();
$("#clientInfoNew").show();
},
minLength: 2
}).blur(function() {
getCardDetails($(NewCardNumber), $(NewCardId), 'newCardSegments', true);
});
$(OldCardNumber).autocomplete(
{
source: function(request, response) {
$.ajax({
url: '/LoyaltyWebApplication/Suggestion/GetCardSuggestions',
dataType: "json",
data: {
str: $(OldCardNumber).val()
},
success: function(data) {
response($.map(data, function(item) {
var label = "";
if (item.Fname != null) label += item.Fname;
if (item.Lname != null) label += " " + item.Lname;
if (label.trim() != '') label = " (" + label.trim() + ")";
return {
value: item.CardNumber,
label: item.CardNumber + label
}
}));
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
},
select: function(event, ui) {
getCardDetails($(OldCardNumber), $(OldCardId), 'oldCardSegments', false);
$("#oldCardSegments").hide();
},
minLength: 2
}).blur(function() {
getCardDetails($(OldCardNumber), $(OldCardId), 'oldCardSegments', false);
});
function getCardDetails(cardNumHolder, cardIdHolder, segmentTablePlace, isNew) {
$.getJSON('/LoyaltyWebApplication/LOV/SetId?lovType=ReplacementLOV&lovValue=' + cardNumHolder.val(), null,
function(data) {
$("#clientInfo" + ((isNew) ? "New" : "Old")).show();
if (cardNumHolder.val() == '') {
return;
}
var i;
for (i = 0; i < data.otherNames.length; i++) {
$("#" + data.otherValues[i] + (isNew ? "New" : "Old")).text(data.otherNames[i]);
}
cardIdHolder.val(data.Id);
$.getJSON('/LoyaltyWebApplication/Replacement/ClientSegmentsList?clientId=' + data.Id + "&no_cache=" + Math.random, function(data) {
$("#" + segmentTablePlace).find('tbody').empty();
if (data.length > 0) {
$.each(data, function(index) {
$("#" + segmentTablePlace).find('tbody').append("<tr><td>" + data[index].SegmentCode + "</td><td>" + data[index].SegmentName + "</td></tr>");
});
$("#" + segmentTablePlace).show();
}
});
});
}
$("#resetVal").click(function() {
$("#NewCardOrAccountNumber").attr("value", "");
$("#NewCardOrAccountNumber").val("");
$("#NewCardId").attr("value", "");
$("#NewCardId").val("");
$("#clientInfoNew").hide();
$("#OldCardOrAccountNumber").attr("value", "");
$("#OldCardOrAccountNumber").val("");
$("#OldCardId").attr("value", "");
$("#OldCardId").val("");
$("#clientInfoOld").hide();
return false;
});
});
</script>
I have a Dojo DataGrid with a few rows of data. When I click on a row, I have a TabContainer created in another <div>. Here's what it ends up looking like:
The formatting for the TabContainer is incorrect. However, after I do an "Inspect Element", the formatting corrects itself:
However, the Submit button disappears after the formatting is corrected.
Here's the code I use to create the DataGrid and TabContainer:
<div id="r_body">
<div id="r_list">
</div>
<div id="r_form">
<div data-dojo-type="dijit/form/Form" id="parameters_form" data-dojo-id="parameters_form" encType="multipart/form-data" action="" method="">
{% csrf_token %}
<div>
<div id="r_tab_container"></div>
</div>
<div>
<p></p>
<button id="submit_parameters" dojoType="dijit/form/Button" type="submit" name="submitButton" value="Submit">
Submit
</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
require([
"dijit/layout/BorderContainer",
"dijit/layout/ContentPane",
"dojox/grid/DataGrid" ,
"dojo/data/ItemFileWriteStore" ,
"dojo/dom",
"dojo/domReady!"
], function(BorderContainer, ContentPane, DataGrid, ItemFileWriteStore, dom){
// create a BorderContainer as the top widget in the hierarchy
var bc = new BorderContainer({
style: "height: 500px; width: 230px;"
}, "r_list");
/*set up data store*/
var data = {
identifier: "id",
items: []
};
data.items.push({ id: 'some_id', description: 'some_description',
var store = new ItemFileWriteStore({data: data});
/*set up layout*/
var layout = [[
{'name': 'Title', 'field': 'description', 'width': '200px', 'noresize': true}
]];
/*create a new grid*/
var r_list_grid = new DataGrid({
region: "left",
id: 'r_list_grid',
store: store,
structure: layout,
rowSelector: '0px'
});
bc.addChild(rt_list_grid);
bc.startup();
list_grid.on("RowClick", gridRowClick);
function gridRowClick(evt){
var idx = evt.rowIndex;
var rowData = list_grid.getItem(idx);
var r_url = rowData['url'][0];
var r_id = rowData['id'][0]
require(["dojo/dom", "dojo/request/xhr", "dojo/dom-form", "dijit/layout/TabContainer", "dijit/layout/ContentPane", "dojo/ready", "dojo/domReady!"],
function(dom, xhr, domForm, TabContainer, ContentPane, ready){
var url = window.location.pathname + "dev/" + r_id + "/" + r_url + "/";
xhr(url, {
method: "get"
}).then(
function(response){
var json_response = JSON.parse(response);
var fields_dict = json_response['fields_dict'];
var tc = new TabContainer({
style: "height: 100%; width: 100%;"
}, "r_tab_container");
for(var key in fields_dict) {
var content_string = '';
var fields = fields_dict[key];
for(var field in fields) content_string += '<div>' + field + '</div>';
var tcp = new ContentPane({
title: key,
content: content_string
});
tc.addChild(tcp);
}
tc.startup();
},
function(error){
//Error stuff
}
);
});
}
});
</script>
So what's going here and how do I fix the TabContainer formatting? Thanks!
I had to do a tc.resize(); after I do the tc.startup();
I am refering to the simpledemo in this question http://demo.swfupload.org/v220/simpledemo/index.php
I want to be able to pass a variable which is set by a dropdown menu.
the uploader is initiated by
var swfu;
window.onload = function() {
var settings = {
flash_url : "<?php global_data::show_admin_dir(); ?>SWFUpload v2.2.0.1 Samples/demos/swfupload/swfupload.swf",
upload_url: "<?php global_data::show_admin_dir(); ?>upload.php",
post_params: {"PHPSESSID" : "<?php echo session_id(); ?>" },
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: false,
// Button settings
button_image_url: "images/TestImageNoText_65x29.png",
button_width: "95",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">UPLOAD</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,
// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete // Queue plugin event
};
swfu = new SWFUpload(settings);
};
and the form is as follows
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p><label>Category: </label><input type="radio" name="for" class="radio" value="category" checked="checked" /><select name="foo"><option>...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<p><label>Product: </label><input type="radio" name="for" class="radio" value="category" /><select disabled="disabled"><option name="foo">...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div>
</form>
if anyone could point me in the right direction it would be much appreciated.
###### EDIT #####
I may have found a way...
using post_params: {"PHPSESSID" : "<?php echo session_id(); ?>", "PR" : thing },
in the init settings and wrapping it all in a function
function loader( thing ) {
....
}
and then using
$(document).ready(function(){
$('select[name=foo]').change(function(){
loader( $(':selected', this).text() );
});
});
it will work, but if i change the select option a second time before uploading it will get an error and only send the first choice instead of the second...
I was trying to do a similar thing and after finding this solution and discussing it with my collegue, we solved it yet another way using the Javascript API available with swfupload.
We were trying to pass a quality setting along with video uploads. Ultimately the solutions to this problem involve how to change post_params. To start with post_params will be the default value of the dropdown:
var selected_quality = $('select#quality-".$dirId." option:selected').val();
...
post_params: {'quality' : selected_quality},
Then you can use the addPostParam method (located in swfupload.js) to update this when options are selected in your dropdown.
$('select#quality-".$dirId."').change(function () {
swfu.addPostParam('quality' , this.value);
});
I have solved this problem in two ways (both using jquery): cookies and mysql. The concept would be a
$('select[name=foo]').change(function(){
$.cookie('dropdown', $(this).val());
});
so that when you change the dropdown, you now have a cookie. in upload.php you can then call that cookie and use it as your variable.
The other option was
$('select[name=foo]').change(function(){
$.post('updatedatabase.php', {'dropdown': $(this).val()});
});
Then you'd call your database from upload.php to get the last value of your dropdown. neither way is very elegant, but I've gotten them working before. I would love if someone posted a more elegant solution.
######## EDIT #######
Right this works a charm.
$(function() {
function loader( thing ) {
var settings = {
flash_url : admin_dir + "SWFUpload v2.2.0.1 Samples/demos/swfupload/swfupload.swf",
upload_url: web_root + "pm_admin/upload_image",
post_params: { "aj" : "true", "PR" : thing },
file_size_limit : "100 MB",
file_types : "*.*",
file_types_description : "All Files",
file_upload_limit : 100,
file_queue_limit : 0,
custom_settings : {
progressTarget : "fsUploadProgress",
cancelButtonId : "btnCancel"
},
debug: false,
// Button settings
button_image_url: "images/TestImageNoText_65x29.png",
button_width: "95",
button_height: "29",
button_placeholder_id: "spanButtonPlaceHolder",
button_text: '<span class="theFont">UPLOAD</span>',
button_text_style: ".theFont { font-size: 16; }",
button_text_left_padding: 12,
button_text_top_padding: 3,
// The event handler functions are defined in handlers.js
file_queued_handler : fileQueued,
file_queue_error_handler : fileQueueError,
file_dialog_complete_handler : fileDialogComplete,
upload_start_handler : uploadStart,
upload_progress_handler : uploadProgress,
upload_error_handler : uploadError,
upload_success_handler : uploadSuccess,
upload_complete_handler : uploadComplete,
queue_complete_handler : queueComplete // Queue plugin event
};
swfu = new SWFUpload(settings);
};
function pre_load(){
var data = '';
data += '<div class="fieldset flash" id="fsUploadProgress">';
data += ' <span class="legend">Upload Queue</span>';
data += '</div>';
data += '<div id="divStatus">0 Files Uploaded</div>';
data += '<div>';
data += ' <span id="spanButtonPlaceHolder"></span>';
data += ' <input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />';
data += '</div>';
return data;
}
/* args stores the input/select/textarea/radio's name and then it's value and then passes a single serialised string when uploading */
/* then use a trigger to update the array, off focus, change, keyup... along thos lines on a class set for all inputs, selects and so on... works a treat */
var args = {};
$('.radio').click(function(){
var ob = $(this).siblings('select');
$('#uploader-wrapper').html(pre_load());
$('.radio').siblings('select').attr('disabled', 'disabled');
ob.removeAttr('disabled');
args[$(this).attr('name')] = $(this).val();
args[ob.attr('name')] = $(':selected', ob).text();
loader( $.param(args) );
})
$('select[name=foo]').change(function(){
var ob = $(this);
$('#uploader-wrapper').html(pre_load());
args[ob.attr('name')] = $(':selected', ob).text();
loader( $.param(args) );
});
});
with form:
<form id="form1" action="index.php" method="post" enctype="multipart/form-data">
<p><label>Category: </label><input type="radio" name="for" class="radio" value="category" checked="checked" /><select name="foo"><option>...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<p><label>Product: </label><input type="radio" name="for" class="radio" value="category" /><select disabled="disabled"><option name="foo">...</option><?php global_data::show_breadcrum_list( 'option', " / " ); ?></select></p>
<div id="uploader-wrapper">
<div class="fieldset flash" id="fsUploadProgress">
<span class="legend">Upload Queue</span>
</div>
<div id="divStatus">0 Files Uploaded</div>
<div>
<span id="spanButtonPlaceHolder"></span>
<input id="btnCancel" type="button" value="Cancel All Uploads" onclick="swfu.cancelQueue();" disabled="disabled" style="margin-left: 2px; font-size: 8pt; height: 29px;" />
</div>
</div>
</form>