I am implementing an edit feature for 3 related models..
and to divide the work .. i implemented 3 tabs using bootstrap extensions...now each tab contains textfields, drop downs, etc., now the contents of the text and the dropdowns, radio buttons etc are pre-loaded for the user; since this is an edit feature, it would be convenient for them if their choices were retained, and that they only need to change specific fields that they want to change without really having to re-do the entire form.
Each form in a tab has its own independent "Save" button that saves the model and then switches to the next tab after refresh.
Here's what i'm trying to do, (and quite having a hard time )..
I'm sure everybody has a facebook account here.. remember when you try to write a status update, or when you are chatting with somebody and then you click a button that redirects to another page?
Then a dialog box (or modal?) will alert you that you haven't finished your post yet, and that it gives you an option whether to leave or to stay in the page?
Similar to what i'm trying to do; i'm trying to alert the user if he/she wants to save or discard his changes (if there are changes made) before he switches to another tab.. I really have no idea how to do this..
on how the widget works..is abstracted (or i haven't found it yet atleast), and unlike in java where i can easily search for "Events" onChange() or something..i'm new to php and yii.. any idea ,on how to do it, what to use, or a sample code will be really helpful guys.. Thanks a lot!
You could use a global var like var saved=false to check your form has been saved.
To catch the on change of your forms:
$('form :input').change(function(){saved=false;});
See: jquery get all form elements: input, textarea & select
When the user left the page you could fire a beforeunload:
$(window).on('beforeunload', function() {
if(!saved) return 'Leave page?';
});
See also:
Dialog box runs for 1 sec and disappears?
catching beforeunload confirmation canceled?
To catch the tab change you could use a default confirm (http://www.w3schools.com/js/js_popup.asp):
$('#myTab a').click(function (e)
{
e.preventDefault();
if(!saved)
{
if(confirm('Leave tab?'))
{
$(this).tab('show');
}
}
else
{
$(this).tab('show');
}
});
Or you could try to build your own confirm dialog:
Note it seems you can't catch the window beforeunload but for the tab change:
html:
<ul class="nav nav-tabs" id="myTab">
<li class="active">Home</li>
<li>Profile</li>
<li>Messages</li>
<li>Settings</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">...</div>
<div class="tab-pane" id="profile"><form><input type="text"><input type="submit" class="btn btn-success"></form></div>
<div class="tab-pane" id="messages">...</div>
<div class="tab-pane" id="settings">...</div>
</div>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<p>Form not saved!</p>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button id="leavetab" class="btn btn-primary">Leave tab</button>
</div>
</div>
javascript:
var saved = true;
var confirmed = false;
var thistab = null;
function checksave()
{
return saved;
}
$(function () {
$('#myTab a:last').tab('show');
$('#myTab a').click(function (e)
{
e.preventDefault();
thistab = $(this);
if(!checksave()){ $('#myModal').modal(); return false;}
thistab = null;
if(saved || confirmed)
{
$(this).tab('show');
saved = false;
confirmed = false;
}
});
//see: https://stackoverflow.com/questions/12862601/jquery-get-all-form-elements-input-textarea-select
$('form :input').change(function(){saved=false; confirmed = false;});
$('#myModal').on('hidden', function () {
return false;
});
// modal click set confirmed to true
$('#leavetab').click(function()
{
{
$('#myModal').modal('hide');
thistab.tab('show');
saved = false;
confirmed = false;
}
});
});
Related
I created a list of users in clickable cards, and when we click on the card, a modal popup appear.
I want now to display the detail of the user in theses popup but I don't really know how I have to do for displaying on the popup, the data of the user on which I click.
there is my List code :
<div class="container employees">
<div class="row">
<f:for each="{users}" as="user">
<div class="card card-annuaire">
<div class="card-body">
<h5 class="card-title">{user.firstname} {user.lastname}</h5>
<div class="links">
<ul>
<li class="loc">{user.address}</li>
<li class="tel">{user.telephone}</li>
<li class="service">{user.title}</li>
<li class="loc">{user.address}</li>
</ul>
</div>
</div>
</div>
</f:for>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<ul>
<li class="mail"></li>
<li class="tel"></li>
<li class="service"></li>
<li class="loc"></li>
<li class="comp"></li>
</ul>
</div>
</div>
controller :
public function listAction()
{
$users = $this->frontendUser->findAll();
$this->view->assign('users', $users);
}
Is my request possible with my current code?
My modal works perfectly, I just need to add my data
Someone have an Idea to how can I do it ?
Update : solved with some Jquery code to copy my data already existing :
<script>
const modal = $('#exampleModal');
$('.card-annuaire').click(function () {
const divAnnuaire = $(this);
$('.modal-title', modal).text($('.card-title', divAnnuaire).text());
$('li.tel', modal).text($('.tel', divAnnuaire).text());
$('li.service', modal).text($('.service', divAnnuaire).text());
$('li.loc', modal).text($('.loc', divAnnuaire).text());
})
</script>
The handling of the modal is a question of javascript.
If you have all data in each block of the user list you can add some javascript to each block which copies this data from the current block (this) into your modal and then unhide the modal.
On hiding the modal you don't need to do anything to the included data, as the next click (which also can occur if the modal already is visible) will fill in the data from the clicked data block.
If in your modal more data should be visible than you stored in your list you need to do something more:
you need the ID of the data to get the whole user-record by ajax call.
but otherwise the handling is the same: on each list block you have an eventhandler, which is triggered by a click and which uses data from the block (all fields, or just the uid for an ajax-call to get all data) and insert this data into the modal.
Good day all,
I have tried visiting this page: https://web.dev/customize-install/, stackover flow questions and google pages but I still cannot get it write.
I am trying to achieve three things with my PWA app:
Open "cache" and get files with the install event.
Prevent the default PWA from install using "beforeinstallprompt" listener.
Display a bootstrap modal with a "download" button.
When that button is clicked, trigger the "fetch" event which installs the app.
I am able to do 1 and 2.
I am triggering my modal on main.js. I tried in the service worker but I could not.
The download button on the modal also does not
index.php
<div class="modal fade" id="myModal3" role="dialog">
<div class="modal-dialog">
<div class="modal-content" >
<div class="modal-body">
<center><p><i class="fa fa-arrow-circle-down"></i></p>
<h5 style="margin-top:0vh;" >Download App</h5>
<p>Download our super cool app.
<div >
<div class="wrap-login100-form-btn" >
<div class="login100-form-bgbtn"></div>
<button class="login100-form-btn" class="AndaniDownload" id="btnDownloadAppOffline" >
Download </button>
</div>
</div>
</center>
</div>
</div>
</div>
</div>
Main.js
$(document).ready(function(){
$('#myModal3').modal('show');
});
pwabuilder-sw.js
importScripts('https://storage.googleapis.com/workbox-cdn/releases/5.1.2/workbox-sw.js');
const CACHE = "pwabuilder-page";
const offlineFallbackPage = "offline.html";
self.addEventListener("message", (event) => {
if (event.data && event.data.type === "SKIP_WAITING") {
self.skipWaiting();
}
});
self.addEventListener('install', async (event) => {
event.waitUntil(
caches.open(CACHE)
.then((cache) => cache.add(offlineFallbackPage))
);
});
if (workbox.navigationPreload.isSupported()) {
workbox.navigationPreload.enable();
}
self.addEventListener('fetch', (event) => {
if (event.request.mode === 'navigate') {
event.respondWith((async () => {
try {
const preloadResp = await event.preloadResponse;
if (preloadResp) {
return preloadResp;
}
const networkResp = await fetch(event.request);
return networkResp;
} catch (error) {
const cache = await caches.open(CACHE);
const cachedResp = await cache.match(offlineFallbackPage);
return cachedResp;
}
})());
}
});
self.addEventListener('beforeinstallprompt', event => {
event.preventDefault();
var button =self.querySelector('.AndaniDownload');
//button.removeAttribute('hidden');
button.addEventListener('click', () => {
event.prompt();
button.setAttribute('disabled', true);
});
});
I am fetching the details of a user according to Id on button click in a popup in laravel but It is showing some error.
This is viewuser.blade.php
<div class="modal fade" id="myModal">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Modal Heading</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<table class="table table-bordered">
<tr>
<td>{{$usersview->id}}</td>
<td>{{$usersview->firstname}}</td>
<td>{{$usersview->filename}}</td>
</tr>
</table>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
This is viewparticipant.blade.php in which I have a button View. When the user will click on this button a popup will open and show the details according to Id.
<td>
View
</td>
My Controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Session;
use App\Imageupload;
class ParticipantController extends Controller
{
public function show($id)
{
$usersview = Imageupload::find($id);
return View::make('viewuser', compact('usersview'));
}
}
My Web.php
Route::get('/participant/show/{id}','ParticipantController#show');
The error is showing that unknown variables in modal.
well you only have $usersview in your blade file and you're calling $row->id in viewparticipant.blade.php , which should be the $usersview->id instead
after Edit -->
so you need to make an ajax call to the function you want to get the results. the ajax must contain the id of the user so you should get the id some how. I usually define an on click function and get the id. then on the same click trigger an ajax call, something like this:
$('#user').on('click', function (event) {
$.ajax({
url: '/users?user_id=' + $(this).val(),
success: function (data) {
// parse the data
},
fail: function () {
// do something in case of failure
}
});
});
$(this).val(); is the id here, I assumed you would store that in an input
Try this:
<td>
View
</td>
Because laravel is figuring out where you want to place your $row->id variable, and to my guessing it's not passing the variable correctly in your route.
try
#foreach($usersview as $usersview)
<tr>
<td>{{$usersview->id}}</td>
<td>{{$usersview->firstname}}</td>
<td>{{$usersview->filename}}</td>
</tr>
#endforeach
I have number of buttons that open the same bootstrap modal.
Does the script files (JS) need to be called from the main file or from the modal file?
I'm calling the js files inside the modal, include the "jquery-1.11.1.min.js" file and because of that the id that only the first id that i'm sending to the modal is caught.
I made example:
http://80.179.226.44/~israelig/sites/exmytrip/tempFile.php
( try to click more than one time)
I need the "jquery-1.11.1.min.js" inside the modal because i want the "upload images" script to work
I need different the id to be sending to the modal. how can i fix that?
main file:
<li> Send value "1" to modal</li>
<li> Send value "2" to modal</li>
<li> Send value "3" to modal</li>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-md">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Title for modal</h4>
</div>
<div class="modal-body">
</div>
</div>
</div>
</div>
</body>
<script>
// clear model content
$('body').on('show.bs.modal', '.modal', function () {
$(this).removeData('bs.modal');
});
</script>
modal code you can see here:
http://80.179.226.44/~israelig/sites/exmytrip/modalFile.php?id=2
Don't use href="url" I usually set href="javascript:;" now use a data attribute eg data-id="1" now you need to do something like this
http://getbootstrap.com/javascript/#modals-related-target
$('#myModal').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget) // Button that triggered the modal
var id= button.data('id') // Extract info from data-* attributes
//I'm guess that you want some dynamic content - so perhaps an ajax call and replace your elements
})
Yeah and then you can either use the id to replace a element or set a value. Or perhaps send an ajax call to get some more complex content. If you are doing an ajax call have a loading bar to help uses - that is shown when you load and hidden after loading. You can make one here http://www.ajaxload.info/
I am building an application with Codeigniter and Bootstrap.
What I want to do is to have a dropdown menu which can change a status in sql, and then in background via AJAX call PHP script to do that and display a confirmation message - with bootstrap alert. Everything should be done without page refresh.
The problem is that I can't find a solution to pass the variable from drop down to PHP without page refresh via POST.
I am trying to do something like this:
<!-- AJAX which hide the DIV -->
<script>
$(document).ready(function(){
$("#message").hide();
$('#status li').click(function () {
$("#message").show();
$("#success-alert").load('<?php echo base_url() ?>/changestatus/150/', {my_var : $("#my_var").val()});
$("#message").fadeTo(2000, 500).slideUp(500, function(){
$("#message").hide();
});
});
});
</script>
In the above code, I would like to have a link like: /changestatus/150/2
where 150 is a sample lead id, and 2 is a new status choosen from dropdown.
<!-- Alert DIV, which is hidden on load -->
<div id="message">
<div class="alert alert-success" id="success-alert">
<button type="button" class="close" data-dismiss="alert">x</button>
<strong>OK! </strong>
The changes has been done :-)
</div>
</div>
<!-- Dropdown menu -->
<div class="btn-group" id="myDropdown">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
Menu
<span class="caret"></span>
</a>
<ul class="dropdown-menu" id="status">
<li>Chg status to 1</li>
<li>Chg status to 2</li>
<li>Chg status to 3</li>
</ul>
</div>
In the above drop down, I do not know where to put the ID numbers 1,2,3.
and how to send it as my_var to AJAX when user clicks option
..and function in my controller
<?
public function changestatus($lead_id)
{
//read a new status from segment in link...
$new_status = $this->uri->segment(4),
//...or from POST
if(isset($_POST['my_var']))
{
$new_status = $_POST['my_var'];
}
// then will be some call to model which mades changes to DB
echo '...done';
}
?>
I've spent a whole day trying to do without success, please help if you can :)
You can make an extra attribute to all your li and assign them values. Get those data attributes in your jQuery code and pass it to the ajax request page.
<ul class="dropdown-menu" id="status">
<li data="1">Chg status to 1</li>
<li data="2">Chg status to 2</li>
<li data="3">Chg status to 3</li>
</ul>
Change jQuery code as below:
$('#status li').click(function () {
var my_var = $(this).attr('data'); //Use this value for your page
$("#message").show();
$("#success-alert").load('<?php echo base_url() ?>/changestatus/150/', {my_var : my_var});
$("#message").fadeTo(2000, 500).slideUp(500, function(){
$("#message").hide();
});
});
Instead of using $("#success-alert").load() you should use $.post to send post data (enter link description here).
$.load uses GET to fetch data from web server.