Increment/decrement button issue - twitter-bootstrap-3

Html markup:
<td data-title="Qty" class="vertical_text quantity">
<button type="button" class="quantity-left-minus btn btn-danger btn-number" data-type="minus" data-field="">
<span class="glyphicon glyphicon-minus"></span>
</button>
<input class="cart-input" type="text" name="qty[]" id="quantity" value="<?php echo $cart['qty']; ?>">
<button type="button" class="quantity-right-plus btn btn-success btn-number" data-type="plus" data-field="">
<span class="glyphicon glyphicon-plus"></span>
</button>
</td>
Script code:
$(document).ready(function() {
var quantitiy = 0;
$('.quantity-right-plus').click(function(e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
var quantity = parseInt($('#quantity').val()); //10
// If is not undefined
$('#quantity').val(quantity + 1);
// Increment
});
$('.quantity-left-minus').click(function(e) {
// Stop acting like a button
e.preventDefault();
// Get the field name
var quantity = parseInt($('#quantity').val());
// If is not undefined
// Increment
if (quantity > 1) {
$('#quantity').val(quantity - 1);
}
});
});
I'm using bootstrap and Codeigniter. In my shopping cart table there is two button (-)button and (+)button with input field. if there is is single row in my table and when I'm clicking on the (-) button / (+) button the value of input field increment/decrement properly. but my problem is if there is two or more row in my table if I'm clicking to second row or third row (-)button/(+)button the value of first row input field increment/decrement. And when I'm refreshing the page the previous value shows up again. Help to increment/decrement button work properly and the value of input field should be update properly. Thank you.

Related

Pass Form Variable in Primeng Dialogue's (onHide) Function when Clicked on "X" Button

I am using Primeng Dialogue with a Form inside it. Form has a cancel button where I am passing form (ngForm) variable to check if the form is in dirty mode or not. If it is in dirty mode I am showing a cofirmation dialogue. The same thing will happen if the user clicks on "X" button in Primeng Dialogue. I am getting NgForm when I click on "Cancel" button but when I am passing form variable in (onHide) function like (onHide)="Cancel(f)", NgForm data is getting as undefined on Cancel(form: NgForm) function. How I can pass the form variable in Primeng Dialogue's (onHide) function when the form is inside this dialogue?
HTML:
<p-dialog header="Retirement Plan Proposal" [(visible)]="isShowProspectModal"
modal="modal" width="1000" height="590" styleClass="modal-blue proposalModal
stickyFooterModal" appendTo="body" [closeOnEscape]="false" (onHide)="Cancel(f)">
<form style="padding-top:7px;" #f="ngForm" name="prospectDetailForm" *ngIf="isShowProspectModal"
(ngSubmit)="f.form.valid" novalidate autocomplete="off">
<p-footer>
<button [disabled]="(!f.dirty && !isFileUploaded) || isLoadingSave"
*ngIf="isSaveButtonVisible" class="btn btn-primary btn-small mr5"
type="submit"
(click)="saveProspect(true, f)" label="Save">
<i class="fa fa-floppy-o"></i> Save
<span class="icon-spiner" *ngIf="isLoadingSave"></span>
</button>
<button class="btn btn-primary btn-small" *ngIf="isSaveButtonVisible" type="button"
[disabled]="(!f.dirty && !isFileUploaded) || isLoadingSave"
(click)="Cancel(f)" label="Cancel">
<i class="fa fa-close"></i> Cancel
</button>
</div>
</p-footer>
</form>
<p-confirmDialog header="Confirmation" icon="fa fa-question-circle" width="400" appendTo="body">
</p-confirmDialog>
</p-dialog>
Cancel Button Function:
Cancel(form: NgForm) {
if (form.dirty) {
this.confirmationService.confirm({
message: 'Data has been changed in this form. Do you want to cancel?',
accept: () => {
this.isShowProspectModal = false;
}
});
}
}
Step 1:
remove *ngIf from "form" tag to get the form object in ts file using #ViewChild.
Step 2:
declare the form in ts file like:
#ViewChild('f', { static: true }) prospectEditForm: NgForm;
Step 3:
Close(form: NgForm) {
if (this.prospectEditForm && this.prospectEditForm.dirty) {
//do whatever you want
}
}

Add Html element in div vuejs

I have been searching for 4 hours , cant even get my head to understand what to use
basically i want to add a new row (article tag) to a div element , everytime the user press the addbutton
in my method how can i pass this HTMLto the div :
<article class="col-md-11 col-md-offset-1 card" custom_attrib=atrrib_value> <span>
{{NEW VALUE}} - {{NEW VALUE_2}}
</span>
<span >
<button class="btn btn-theme btn-default btn-xs pull-left" #click="deleteItem" ><i class="fa fa-times inline"></i></button>
</span>
</article>
I have to say i need to put some custom attrib on the Article tag each time thats why i want to make a new tag on each request
if we take a look at this https://codepen.io/Pizzi/pen/GMOQXy
when pressing the + (add) a row drops , i want to do the same thing but the important part is the new row with article tag needs new custom_attrib and value everytime
another jsfiddle example : https://jsfiddle.net/50wL7mdz/17736/
instead of those input box will be my article with custom attrib and value
You make an array. When the user clicks "add new" you will append a new item to the array which contains HTML with two input fields. When you append it, Vuejs will re-render the HTML with the changed data.
// Vue.js
new Vue({
el: '#app',
data: {
items:[],
item:['NEW VALUE','NEW VALUE_2'],
},
created(){
this.items.push(this.item);
},
methods:
{
add()
{
this.item = ['</br><input type="text"/>','<input type="text"/></br>'];
this.items.push(this.item);
}
}
})
<h2>Vue.js</h2>
<div id="app">
<article class="col-md-11 col-md-offset-1 card" custom_attrib=atrrib_value>
<span v-for="item in items" ><span v-html="item[0]"></span> - <span v-html="item[1]"></span></span>
<span >
<button v-on:click="add" class="btn btn-theme btn-default btn-xs pull-left">
+
</button>
</span>
</article>
</div>
<!-- Vue.js -->
<script src="https://vuejs.org/js/vue.min.js"></script>

Trigger Bootstrap modal from disabled textbox

I want to Trigger boot-strap model on click of disabled text-box or text Area
I have tried it but it works fine with text box if the text box enabled
<input type="text" data-toggle="modal" data-target="#myModal" disabled="disabled"/>
Disabled elements don't fire click event on all the browsers, or all the inputs.
https://developer.mozilla.org/en-US/docs/Web/Events/click
Try this:
<span class="disabled">
<input type="text" data-toggle="modal" data-target="#myModal" disabled="disabled"/>
</span>
Javascript:
$('span.disabled').on('click', function(event) {
$('#myModal').modal('show');
});
OR if you want to collect the target from the input:
$('span.disabled').on('click', function(event) {
var modal_target = $(this).find('input').data('target');
$(modal_target).modal('show');
});

why document.ready() dont work after fetching data with ajax in div element?

I have a problem with this jQuery function that i use for add and remove box to my page:
jQuery(document).ready(function($){
$('.my2-form .add2-box').click(function(){
var n = $('.text2-box').length + 1;
if( 12 < n ) {
alert('you can't make more than 12 box');
return false;
}
$.post('showselectdatearray.php', { type: 'months', year: 93}, function(result) {
var box_html = $('<p class="text2-box" style="padding: 0px; margin: 0px;"><label for="box' + n + '"><span class="box2-number">' + n + ' </span></label> <input type="text" name="boxes[]" value="" id="box' + n + '" size="8" /> '+resultremoveitem</p>');
box_html.hide();
$('.my2-form p.text2-box:last').after(box_html);
box_html.fadeIn('slow');
box_html.css( 'background-color', '#48b973' );
return false; });
});
$('.my2-form').on('click', '.remove2-box', function(){
$(this).parent().css( 'background-color', '#FF6C6C' );
$(this).parent().fadeOut("slow", function() {
$(this).remove();
$('.box2-number').each(function(index){
var p =index+1;
var str = p+'\xa0\xa0\xa0\xa0';
$(this).text( str );
});
});
return false;
});
$('.my2-form p.text2-box:last').css( 'background-color', '#FFFFFF' );
});
then i use from above script in my code this way:
<div id="showresult12" class="my2-form">
<div>
<input type='button' id='AddMore' name='AddMore' value='add box' class='add2-box' />
</div>
<div style="float: right;" class="scroll10">
<p class="text2-box" style="padding: 0px; margin: 0px;">
<label for="box"><span class="box2-number">1 </span></label>
<input type="text" name="boxes[]" value="" id="box" size="8" />
<?php Show_Select_Date_Array("months",0,0,0,93) ?>
</p>
</div>
</div>
Every thing is OK now and when user click on "add box" button, another box appear and when user click on "remove it" button, one box remove.
I have another part -part2- under this code that fetch from database. after user click on "edit" button that is locate in -part2-, information fetch from database to boxes with php code, but my add and remove button don't work at all. my information fetch with Ajax and replace in new boxes. the 'showresult12' div id completely load again with same data.
what is the problem after replacing div element?!
and what change i must do in my jquery code that it work after div load again?
In your 'var box_html=...' line, there looks to me to be a bit of a syntax error:
'+resultremoveitem</p>');
where 'result' isn't used properly. Should it be something like +result+'<a href... ?
EDIT: If as you say your 'showresult12' div is being emptied and then refilled again dynamically, then your 'add' event handler will always be invalid - it's not using delegation like the 'remove' one.
$('.my2-form').on('click', '.remove2-box', function(){ - this is OK, as it will work for dynamically-created .remove2-box elements.
$('.my2-form .add2-box').click(function(){... - however this is not, as it is only valid for .add2-box elements that were present in the DOM when this handler was created.
So in this scenario, the 'add' hander will not work following your AJAX PHP call.
Furthermore, if you are actually going further and removing and re-adding the .my2-form div (#showresult12) itself, then neither of the handlers will work - you would have to do something like $('body').on('click', '.my2-form .add2-box', function() {....
thanks for your answer but my result fetch from file with name "showselectdatearray.php". it is not important you can remove this
$.post('showselectdatearray.php', { type: 'months', year: 93}, function(result) {
AND result variable in : '+result<a href="#"

Unable to Disbale the DOJO dijit.form.Form

I have a Form and i want to disable the entire form on click of a Button ,please see this code
<div dojoType="dijit.form.Form" id="myForm" jsId="myForm" encType="multipart/form-data"
action="" method="">
<table>
<input type="text" id="name" name="name" required="true" dojoType="dijit.form.ValidationTextBox"
<input type="text" id="dob" name="dob" dojoType="dijit.form.DateTextBox"
</table>
<button dojoType="dijit.form.Button" type=button onClick="console.log(myForm.getValues())">
Get Values from form!
</button>
<button dojoType="dijit.form.Button" type="submit" name="submitButton"
value="Submit">
Submit
</button>
<button dojoType="dijit.form.Button" type="reset">
Reset
</button>
<button dojoType="dijit.form.Button" onClick="callMe()">
Disable IT
</button>
</div>
I have written a function callMe to disable this
function callMe()
{
dijit.byId('myForm').disabled=true;
}
Dijit forms do not have a property "disabled", but rather you have to overwrite the onSubmit event:
dijit.byId('myForm').onSubmit = function () {
// If we return false here, the form will not be submitted.
return myMagicEnabledFlag;
};
Note that you cannot use dojo.connect as you have to modify the return value of the event and not just connect to it.
For disabling the entire form elements, use the "getChildren()" function of the dijit form, which would return the array of all the field widgets of that corresponding form. Then, you need to disable the widgets of that array. See below sample:-
dijit.byId('myForm').onSubmit = function () {
var widgets = dijit.byId('myForm').getChildren();
for(var i=0;i<widgets.length;i++) {
widgets[i].set('disabled', true);
}
//if you need to prevent the form submission & just disable, return false,
//else ignore the following return stmt
return false;
};