i have a modal dialog conataining an ajax.beginform.
on a view i have a list of roles for a selected user, when i click add, the dialog is created using ajax
view:
<div id="popupAgregarRolModal" title="#Res_String.AsaignRol">
<!-- Client Partial, empty for now -->
</div>
<script>
$(document).ready(function () {
$(".AddRolButton").on("click", function (event) {
event.preventDefault();
$.ajax({
url: "Permiso/_GestionarRol?idSelectedUser=" + $("#AdmPerGridBUsquedaUsuarioSelectedRow").val(),
type: "GET",
})
.done(function (result) {
$("#popupAgregarRolModal").html(result).dialog({ modal: true, height: 'auto', width: 'auto', resizable: false });
});
});
});
function closeDialogNuevoRol(Result) {
$("#popupAgregarRolModal").dialog('destroy');
}
</script>
, the dialog contains an ajax.beginform like:
using (Ajax.BeginForm("SetPermiso", "Permiso", new AjaxOptions
{
UpdateTargetId = "ABMPermisos",
InsertionMode = InsertionMode.Replace,
HttpMethod = "POST",
OnSuccess = "closeDialogNuevoRol"
}, new { #id = "AddRolForm" }
)
)
{
.
.
.
the idea is that after i add a new rol to my user, the ajax target upload the list of roles on the view, this is done on my controler by using redirecttoaction if all comprobation and insertion logic hapends, then i whant to close the dialg but i only get
Uncaught Error: cannot call methods on dialog prior to initialization;
attempted to call method 'destroy'
To close a jQuery modal dialog, you can use this:
$("#popupAgregarRolModal").dialog("close");
Hope this helps.
EDIT: Try initializing the modal like this and not inside the click event of the button:
$(document).ready(function () {
$("#popupAgregarRolModal").dialog({ autoOpen: false, modal: true, resizable: false, draggable: false });
});
Then you can have a separate function for the click event.
$(".AddRolButton").click(function () {
//Do stuff
});
This post might help
Related
So I have a vuejs inline event that works great for one, but I want to expand it. Right now it checks for a specific property and the event changes based on what property is there. Issue is, I prefer to keep this inline instead of moving it all to a method in the model. So i guess this would become a big tenerary operation? So it checks to see if oil is there, if so it will trigger the click method. If its food, it will trigger that click2 method and anything else will trigger the click3 method. My goal is to keep this inline.
new Vue({
el: "#app",
data: {
todos: [
{ text: "food", done: false },
{ text: "pasta", done: false },
{ text: "oil", done: true },
{ text: "cheese", done: true }
]
},
methods: {
click:function(){
alert ("one clicked");
},
click2:function(){
alert ("two clicked");
},
click3:function(){
alert ("anything else");
}
}
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
<button v-on:click="todos.text==='tractor'?click(todos): todos.text==='jack'?click2(todos):click(todos)">
click me
</button>
</div>
Just send the todo as a param and do the logic there:
// template
<button v-on:click="click(todo)">
Then inside your component script:
methods: {
click(todo){
switch (todo.text){
case 'oil':
//Call a method or do logic here
this.handleOilTodo();
break;
....
How can I make my components wait for an ajax call to complete before being rendered? Right now, their data objects are empty because the ajax call has not completed when they are mounted.
Additionally, I want all components to have access to this ajax data, which will be refreshed and updated every 30 seconds. What is the best way to achieve this?
//Snippet of what gets return from ajax call
{
121: {
table_info: {
id: "121",
name: "Test",
table_number: "51",
cap: "6",
seating: "OPEN",
position_x: "0.19297285",
position_y: "0.07207237",
participants_in_tables: "5",
count: 5
}
}
}
//Global
var tableData; //This gets set when the Vue ajax call is complete after being mounted
var width = $(document).width();
var height = $(document).height();
//Vue
Vue.component('tables', {
data: () => {
return {
tables: tableData
}
},
template: `
<div id="tableContain">
<div class='table' v-for="table in tables" :style="computeOffsets(table)">
{{table.table_info.name}}
</div>
</div>
`,
methods: {
computeOffsets(table) {
return {
top: (table.table_info.position_x * width) + 'px',
left: (table.table_info.position_y * height) + 'px'
}
}
});
var app = new Vue({
el: '#main',
mounted() {
$.ajax({
method: 'POST',
dataType: 'json',
url: base_url + 'users/getTableAssignments/' + event_id
}).done(data => {
tableData = data; //Set global tableData
});
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.4.2/vue.js"></script>
<div id="main">
<table></table>
</div>
It's better to use created in vue and then get the data with props in component like:
Vue.component('tables', {
props: ['tables']
// ...
});
var app = new Vue({
el: '#main',
data: { tables: [] },
created() {
axios.get('url').then( response => { this.tables = response.data } )
}
});
I prefer axios but u can use ajax if u like :D
And if u like to refresh u can just use intervals but I prefer server side solution like sockets. Im using it in my app with laravel broadcasting, redis and sockets to have a realtime dashboard :D
I want create a dynamic on click append data to tab but I get in the tab undefined. Could you tell me whats wrong? Not quite sure what is the case,
My js
<script type="text/javascript">
$(document).ready(function () {
// Create jqxTabs.
$('#jqxTabs').jqxTabs({ width: 580, height: 200,showCloseButtons: true });
var length = $('#jqxTabs').jqxTabs('length') + 1;
var loadPage = function (url) {
$.get(url, function (data) {
data;
// console.log( $('#content' + length ).text(data));
// console.log(data);
});
}
$('div.s span').click(function() {
var getvalue = $(this).attr('rel');
$('#jqxTabs').jqxTabs('addFirst', 'Sample title',loadPage(getvalue).text());
$('#jqxTabs').jqxTabs('ensureVisible', -1);
});
// $('#jqxTabs').on('selected', function (event) {
// var pageIndex = event.args.item + 1;
// loadPage('pages/ajax' + pageIndex + '.htm', pageIndex);
// });
});
</script>
My html
<div class="s">
<span rel="gen.php">Load</span>
</div>
<div id='jqxWidget'>
<div id='jqxTabs'>
<ul>
</ul>
</div>
</div>
So first check the right syntax for tab control:
HTML:
....
<div id='jqxTabs'>
<ul>
<li></li>
</ul>
<div></div>
</div>
Javascript:
// Create jqxTabs.
$('#jqxTabs').jqxTabs({ width: 580, height: 200, showCloseButtons: true });
$('#jqxTabs').jqxTabs("removeFirst"); //here removes the empty tab
//here the function must return the content, and the ajax must be async false for this purpose
var loadPage = function (url) {
var result = null;
$.ajax({
url: url,
type: 'get',
dataType: 'html',
async: false,
success: function(data) {
result = data;
}
});
return result;
}
$('div.s span').click(function() {
var getvalue = $(this).attr('rel');
$('#jqxTabs').jqxTabs('addFirst', 'Sample title', loadPage(getvalue));
$('#jqxTabs').jqxTabs('ensureVisible', -1);
});
For better understanding check: http://jsfiddle.net/charlesrv/h4573ykv/1/
EDIT: For the new condition, use a custom attribute so checking would be easier:
$('div.s span').click(function() {
var getvalue = $(this).attr('rel');
var opened = $(this).attr('opened');
if (!opened) {
$(this).attr('opened', true);
$('#jqxTabs').jqxTabs('addFirst', 'Sample title', loadPage(getvalue));
$('#jqxTabs').jqxTabs('ensureVisible', -1);
}
});
MVC4: I am new to using WebGrid with MVC. Code below produces WebGrid inside dialog, but pagination does not work in Chrome ( blank page displayed) and in IE : dialog with WebGrid shown , but IE hangs (seem to be doing something and then hangs, no chance to try pagination even).
What is wrong with my code?
Thank you
HomeController.cs
public ActionResult MyReport (int id) // get here on click in SelectList
{
List<MyLocation> myl = MyLocation.GetAllLocations(31); // static method in MyLocation model
return View(myl);
}
public ActionResult MyLocationDetails (int id)
{
LocationDetails ld = new LocationDetails();
List<LocationDetails> model = ld.GetTestLocationDetails(); //model has 20 records
return PartialView(model); // MyLocationDetails partial view to be displayed in Dialog
}
MyReport.cshtml View that should display dialog
#model IEnumerable<MyLocation>
#Html.ActionLink("Location Details", "MyLocationDetails", null, new { id = 234 }, new { #class = "LocDetails" })
<div id="LocDetails-dialog"></div>
<script type="text/javascript">
$(function () {
$('#LocDetails-dialog ').dialog({
autoOpen: false,
width: 400,
resizable: false,
modal: true
});
$('.LocDetails').click(function() {
$('#LocDetails-dialog ').load(this.href, function() {
$(this).dialog('open');
});
return false;
});
});
</script>
MyLocationDetails.cshtml
#model List
<div>
#if (Model != null)
{
if (Model.Count != 0)
{
<div id="divLocDetails">
#{WebGrid grid = new WebGrid(source: Model,
rowsPerPage: 5,
canPage: true
);
grid.SortDirection = SortDirection.Ascending;
}
#grid.GetHtml(
htmlAttributes: new { id = "LocDetails" },
mode: WebGridPagerModes.All,
firstText: "First",
previousText: "Prev",
nextText: "Next",
lastText: "Last",
columns: new[] {
grid.Column("city", header: "City", canSort: true),
grid.Column("country", header: "Country", canSort: false)
}
)
</div>
}
else
{
<label>No results</label>
}
}
</div>
I have div like
var d=dojo.byId('elem');
and I want to put three buttons in d from my code ( when I click on some other div, I have connect on click event).
I tried
var button = new dijit.form.Button({
label: "Click me!",
onClick: function() {
}
},
"progButtonNode");
and
d.appendChild(button);
but it doesn't work. Can anybody help ?
Either:
var button = new dijit.form.Button({
id: "progButtonNode",
label: "Click me!",
onClick: function() {
}
}, d);
or
var button = new dijit.form.Button({
id: "progButtonNode",
label: "Click me!",
onClick: function() {
}
});
d.appendChild(button.domNode); // Should use dojo.place()
The second parameter of a dijit is the container DOM node (in your case "elem"), not your dijit's node.
The object returned is a dijit object, not a DOM node. Use the "domNode" property to get that dijit's DOM node.
Be careful to avoid having multiple buttons with the same id. Should generate a new id for each button, or let dijit generates them for you.
To create dojo button programmatically, node "progButtonNode" must exist on page. For example
HTML:
...
<body>
<button id="progButtonNode" type="button">
</button>
</body>
...
Javascript:
...
dojo.require("dijit.form.Button");
dojo.addOnLoad(function() {
// Create a button programmatically:
var button = new dijit.form.Button({
label: "Click me!",
onClick: function() {
// Do something:
dojo.byId("result1").innerHTML += "Thank you! ";
}
},
"progButtonNode");
});
...
Dojo button examples