why bootstrap modal is not working - database

I have created forms to allow me to select member button than retrieve information from the database into the table and update it after made change is working great.
Now I want to move that forms into the BOOTSTRAP MODAL but is not working, when I click the button just slides down bootstrap model AND then DISAPPEAR right away.
What did I miss it…
<form method='post'>
<input type='hidden' name='id' value='" . $row['id_boxe'] . "'/>
<input type='submit' name='update' value='Update' href='#modal-view' role='button' class='btn' data-toggle='modal''/>
</form>
</td>
Retrieve information from database after click button.. (outside modal)
<?php
if (isset($_POST['id'])) {
$id = trim($_POST['id']);
$sql = "SELECT * FROM boxes where id_boxe = " . $id;
$result = $db->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$title = $row['title_boxe'];
$status = $row['status'];
$side = $row['side'];
}
$result->close();
}
?>
Section bootstrap modal: (echo information inside modal)
<div class="modal fade" id="modal-view" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×
</button>
<h4 class="modal-title" id="myModalLabel">
Modal title
</h4>
</div>
<div class="modal-body">
<form method="post" class="col-md-6">
<?php if(isset($id)) {?>
<input type="hidden" name="id_boxe" value="<?=$id?>"/>
<?php } ?>
<div class="form-group">
<label for="boxe_title">Boxe Title</label>
<input type="text" class="form-control" name="boxe_title" value="<?php if(isset($title)) echo $title; ?>">
</div>
<div class="checkbox">
<select name="side">
<?php if(isset($side) && $side == 1) { ?>
<option value="1" selected>right</option>
<?php } else {?>
<option value="1">right</option>
<?php } ?>
<?php if(isset($side) && $side == 2) { ?>
<option value="2" selected>left</op)tion>
<?php } else {?>
<option value="2">left</option>
<?php } ?>
</select>
</div>
<div class="select">
<?php if(isset($status) && $status == 1) { ?>
<label><input type="checkbox" name="visibility" checked> Visible in the Menu</label>
<?php } else {?>
<label><input type="checkbox" name="visibility" > Visible in the Menu</label>
<?php } ?>
</div>
<?php if (isset($_POST['id'])) { ?>
<button type="submit" name="updatedata" class="btn btn-default">Update</button>
<?php } else { ?>
<button type="submit" name="add" class="btn btn-default">Add</button>
<?php } ?>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-primary">
Save changes
</button>
</div>
</div>
</div>
</div>
My question is that what did I missed to show bootstrap modal with profile information instead of disappear bootstrap modal!
Is works fine before bootstrap modal but after moved that forms to bootstrap modal is not working..
What I missed!
Thank you for your help…
AM

My guess is that the form with the submit button is causing the problem, perhaps it is showing the modal quickly because of the data-toggle on the submit button but then since you are triggering a form submit it reloads the page causing the modal to disappear.
Try changing your button to:
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#modal-view">Launch demo modal</button>
Like it shows in the demo on bootstrap's site.
Also you might want to read up on SQL Injection because your code looks vulnerable.
It is hard to tell what the problem is with the modal without seeing a full HTML output, can you provide that in jsfiddle?

Related

ng click in button dont logout

I'm doing a system to idle a user after 1 minute and I'm opening a modal with a button to alert the user with a button inside which redirects to login page.
controllerScope.logout = function () {
alert("logout");
$location.path('/');
AuthService.logout(controllerScope.user).then(function (result) {
$state.go('user.signin');
});
};
In my view:
<script type="text/ng-template" id="timedout-dialog.html">
<div class="modal-header">
<h3>Oh, Snap! You've Timed Out!</h3>
</div>
<div class="modal-body">
<p>
You were idle too long. Click the button below to be redirected to the login page and begin again.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger btn-small" ng-click="doLogout()">Back To Login</button>
</div>
</script>
Why when I click on my "back to login" on modal it doesn't go to my function on the controller? I tried to pop up an alert, a simple thing but event that doesn't work
You need to make below changes, since you use controller as syntax :
In controller it should be like var controllerScope = this
In HTML controller declaration be like : ng-controller ="yourcontrollername as controllerScope"
During calling logout, it should be like ng-click="controllerScope.logout()"
Update
Your plunker has many issues, this even doesn't run angular.
So I created this Fiddle with minimal possible code to show the things to be done.
In general :
use controller as alias., for logout ng-click="inventoryCtrl.openNewDeviceModal()" and for opening modal popup use alias as well controller: 'InventoryController as inventoryCtrl',
You set doLogout() function into your ng-click. Would you mean logout() as in your controller ?
Your ng-click method is wrongly called: Kindly change ng-click="controllerScope.logout()"> instead of ng-click="doLogout()">
Update
I have uploaded my code to share with you https://jsfiddle.net/y0xrgjaf/
Your template code in outside of the controller div tag. You should add your all html code inside of the main div
<div ng-controller="controllername">
//all code should be here
</div>
Copy this below code and paste it
<div class="row" ng-controller="InventoryController as inventoryCtrl" >
<div class="col-md-12">
<div class="panel mb25">
<div class="panel-body">
<table class="table mb0 table-striped datatable" ui-jq="dataTable" ui-options="devicesData">
<thead>
<tr>
<th></th>
<th>S/N</th>
<th>IP</th>
<th>Name</th>
<th>Manufacturer</th>
<th>Model</th>
<th>Organization</th>
<th style="width:70px;"></th>
</tr>
</thead>
</table>
</div>
</div>
<div>
<button class="btn btn-default" ng-click="openNewDeviceModal()">Add Device</button>
</div>
</div>
<script type="text/ng-template" id="newDeviceModalContent.html">
<div class="modal-header">
<h3 class="modal-title" ng-bind="deviceModalTitle"> Add Device</h3>
</div>
<div class="modal-body">
<form class="form-horizontal bordered-group" role="form" name="addDeviceForm">
<div class="form-group">
<label class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="name" ng-model="newdevice.data.name" required>
<span ng-show="addDeviceForm.name.$invalid">The name is required.</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">S/N</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="sn" ng-model="newdevice.data.sn" required>
<span ng-show="addDeviceForm.sn.$invalid">The S/N is required.</span>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Model</label>
<div class="col-sm-10">
<select class="form-control" ng-model="newdevice.device_type_id" ng-options="type.id as type.model for type in deviceTypes">
<option value="">None</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Organization</label>
<div class="col-sm-10">
<select class="form-control" ng-model="newdevice.organization_id" ng-options="organization.id as organization.data.name for organization in organizations">
<option value="">None</option>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn btn-default btn-sm" ng-click="saveDevice()" ng-disabled="addDeviceForm.name.$invalid || addDeviceForm.sn.$invalid">Save</button>
<button class="btn btn-default btn-sm" ng-click="cancel()">Cancel</button>
</div>
</script>
<script type="text/ng-template" id="timedout-dialog.html">
<div class="modal-header">
<h3>Oh, Snap! You've Timed Out!</h3>
</div>
<div class="modal-body">
<p>
You were idle too long. Click the button below to be redirected to the login page and begin again.
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger btn-small" ng-click="inventoryCtrl.logout()">Back To Login</button>
</div>
</script>
</div>

How to use ng-model, in a modal. angularjs?

I have the following modal, With ng-model item
<div class="uk-modal" id="modal_header_footer">
<div class="uk-modal-dialog">
<div class="uk-modal-header">
<h3 class="uk-modal-title">Editar Usuario</h3>
</div>
<form id="form_validation" class="uk-form-stacked">
<div class="uk-grid" data-uk-grid-margin>
<div class="uk-width-medium-1-2">
<div class="parsley-row">
<label for="fullname">user<span class="req">*</span></label>
<input type="text" ng-model="item.user" required class="md-input" md-input />
</div>
</div>
<div class="uk-width-medium-1-2">
<div class="parsley-row">
<label for="fullname">name<span class="req">*</span></label>
<input id="nombre" type="text" name="nombre" ng-model="item.name" required class="md-input" md-input />
</div>
</div>
</div>
<div class="uk-grid" data-uk-grid-margin>
<div class="uk-width-medium-1-2">
<div class="parsley-row">
<label for="email">Email<span class="req">*</span></label>
<input id="email" type="email" name="email" ng-model="item.email" data-parsley-trigger="change" required class="md-input" md-input />
</div>
</div>
</div>
</form>
<div class="uk-modal-footer uk-text-right">
<button type="button" class="md-btn md-btn-flat uk-modal-close">Cerrar</button>
<button type="button" ng-click="EditarUsuario(item)" class="md-btn md-btn-flat md-btn-flat-primary">Aceptar</button>
</div>
</div>
The modal call it from a button belonging to a record in datatable, "data-uk-modal="{target:\'#modal_header_footer\'}""
vm.dtColumns = [
DTColumnBuilder.newColumn('id').withTitle('Id'),
DTColumnBuilder.newColumn('usuario').withTitle('Usuario'),
DTColumnBuilder.newColumn('nombre').withTitle('Nombre'),
DTColumnBuilder.newColumn('email').withTitle('Email'),
DTColumnBuilder.newColumn('telefono').withTitle('Telefono'),
DTColumnBuilder.newColumn('estado').withTitle('Estado'),
DTColumnBuilder.newColumn('created_at').withTitle('Creado'),
DTColumnBuilder.newColumn(null).withClass('parent').withTitle('Acciones').notSortable().renderWith(function(data,type,full){
vm.usuario[data.id] = data;
return ' <i class="md-icon material-icons md-bg-light-blue-900 uk-text-contrast"></i>'+
' <i class="md-icon material-icons md-bg-red-900 uk-text-contrast"></i>';
})
];
I need to pass the data parameter, and so make use of the ng-model in the modal
There is no difference between the way we use ng-model in a modal and any other part of the website.
In your case, I suppose you want to show the user's data displayed which belong to a specific record in the table.
So if your ng-model in the modal belongs to the same controller which contains the edit func, you just need to bind the information passed as parameter to the corresponding ng-model in the modal. When the modal shows up, it will show the bind information in the modal.
Let's say, in your modal you have this:
<div class="parsley-row">
<label for="fullname">user<span class="req">*</span></label>
<input type="text" ng-model="item.user" required class="md-input" md-input />
</div>
Then in your edit function you just have to say
function edit(user){
$scope.item = user; //...item is the var used for binding the information to the modal and user is the var coming from the table
}
This can solved using dummy object. here is a code
<td title="'Payment'"> <button type="button" class="btn btn-info btn-lg pay-btn" data-toggle="modal" data-target="#myModal" ng-click="mommy(obj)" >yuty</button>
<!-- Modal content-->
<div id="myModal" class="modal fade" role="dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-body">
<form>
<div class="form-group">
<label>Amout</label>
<input type="Number" ng-model="vvv.payment">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal" ng- click="mono=false">Close</button>
<button type="button" class="btn btn-default" ng- click="modify(vvv._id,vvv)">Submit</button>
</div>
</div>
dummy object
$scope.mommy = function(h){
console.log(h.payment);
$scope.vvv = h;
}
hope you get to understand it,
This is better way to use it

How to horizontally position elements for a pagination toolbar using Boostrap?

I'm working on an AngularJS project and in one of my views I have a table that will have pagination implemented on it. I want the controls for the pagination to be as follows:
Stacked horizontally, to have a Previous button, a text indicating the page of total of pages, and a Next button.
A select containing the number of elements per page desired to visualize on the table, and a text just saying "elements per page"
A text input to enter the number of page, and a Go to button that will load the indicated page.
All of these have to be sorted horizontally.
I defined this components like this in my view:
<div class="container">
<div class="row">
<div class="col-md-6">
<ul class="pagination pagination-sm">
<li >Anterior</li>
<li ><a>1 de 10 páginas</a></li>
<li>Siguiente</li>
</ul>
</div>
<div class="col-md-3">
<select class="form-control" ng-model="uc.defaultSelect" ng-options="n for n in uc.elementsPerPage" ></select>
<label>elementos por página</label>
</div>
<div class="col-md-3">
<div class="input-group">
<input type="text" class="form-control" placeholder="Ir a página..." />
<span class="input-group-btn">
<button class="btn btn-default" type="button">Ir</button>
</span>
</div>
</div>
</div>
</div>
But the end result I'm getting looks like this
The nav buttons look completely off line, the select is too big and it's pushing the label to a new line, the one that looks fine is the go to page input.
What kind of styling can I use with Bootstrap to achieve the look I desire?
In the end I had to give up on using the paginationstyle and changed to button-group, I removed some labels and ended up with this:
<div class="container">
<div class="row">
<div class="col-md-6 btn-group">
<button type="button" class="btn btn-default" ng-click="uc.previousPage()">Anterior</button>
<a class="btn btn-default disabled">1 de 10 páginas</a>
<button type="button" class="btn btn-default" ng-click="uc.nextPage()">Siguiente</button>
</div>
<div class="col-md-3">
<select class="form-control form-control-sm" ng-model="uc.defaultSelect" ng-options="n as (n + ' por página') for n in uc.elementsPerPage" ></select>
</div>
<div class="col-md-3">
<div class="input-group">
<input type="text" ng-model="uc.page" class="form-control" placeholder="Ir a página..." />
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="uc.goToPage()">Ir</button>
</span>
</div>
</div>
</div>
</div>
Now I get this in my view:
I can just add some color to it if as necessary and I just got a pretty looking pagination toolbar.

form-control attribute is not adjusting to bootstrap modal template

I am trying to create a modal with form using angularjs and bootstrap.
First I created the form and now I am trying to put it to modal template but the form-control is sliding out of the modal as you can see in the link attached.
<div class="modal-header">
<h3 class="modal-title">Add New Review</h3>
</div>
<div class="modal-body">
<form role="form">
<fieldset>
<legend>Basic Information</legend>
<div class="container">
<div class="form-group">
<label for="address">Address</label>
<input type="text" id="address" name="address" class="form-control col-sm-1"
ng-model="editableReview.address"
required>
</div>`enter code here`
</fieldset>
</form>
</div>
<div class="modal-footer">
<div class="col-sm-offset-10">
<input type="button" class="btn btn-default" value="Cancel" ng-click="cancelForm()"/>
<input type="submit" class="btn btn-primary" value="Submit" ng-click="submitForm()"/>
</div>
</div>
this is what I get:
It seems like your problem is with the div class, specifically the container. I think you should try to delete this line:
<div class="container">
(and ofcourse its closing tag: </div>, and see if it fixes your issue.
Let me know if that helps.

use form under another form with seprate button

I want use a form under another form in angularjs. First form (form1) is a form-wizard. I want use another form in form1 and then goto another step of form-wizard. I want add some data in form2 and push data in a list and then by form 1, goto another step. I have below code:
<form class="tab-pane" id="second-1" name="second-1Form" rc-submit rc-step>
<form ng-submit="form2()">
<div class="form-group">
...
</div>
<div class="form-group">
...
</div>
<div class="form-group">
<button>Submit</button>
</div>
</form>
</form>
<div class="form-group">
<div class="pull-right">
<a class="btn btn-default" ng-click="rc.sampleWizard.backward()"ng-show="rc.sampleWizard.currentIndex > rc.sampleWizard.firstIndex">Back</a>
<a class="btn btn-primary" data-loading-text="Please Wait..." ng-click="rc.sampleWizard.forward()"ng-show="rc.sampleWizard.currentIndex < rc.sampleWizard.navigationLength">Continue</a>
<a class="btn btn-primary" ng-click="rc.sampleWizard.forward()"ng-show="rc.sampleWizard.currentIndex == rc.sampleWizard.navigationLength">Complete</a>
</div>
</div>
and in controller:
$scope.addBolouk = function(){
$scope.BoloukRadif.push($scope.formdata);
};
but when I complete form2 and click on submit, data don't add to list and submit of form-wizard is work and page is goto next form-wizrd.
I want add data to list by using first form and then goto next form-wizard. How can I seprate button of form2 from button of form-wizard? How can I resolve this problem?
You can't have a form inside a form, but you can use the ng-form directive,
<form class="tab-pane" id="second-1" name="second-1Form" rc-submit rc-step>
<ng-form>
<div class="form-group">
...
</div>
<div class="form-group">
...
</div>
<div class="form-group">
<button ng-click="form2()">Submit</button>
</div>
</ng-form>
</form>
<div class="form-group">
<div class="pull-right">
<a class="btn btn-default" ng-click="rc.sampleWizard.backward()"ng-show="rc.sampleWizard.currentIndex > rc.sampleWizard.firstIndex">Back</a>
<a class="btn btn-primary" data-loading-text="Please Wait..." ng-click="rc.sampleWizard.forward()"ng-show="rc.sampleWizard.currentIndex < rc.sampleWizard.navigationLength">Continue</a>
<a class="btn btn-primary" ng-click="rc.sampleWizard.forward()"ng-show="rc.sampleWizard.currentIndex == rc.sampleWizard.navigationLength">Complete</a>
</div>
</div>

Resources