Having problems with Vue and images on my modal - html

I have cards that shows the name, description,price and an image, this works but when I press more info I basiclly want to show the same stuff but with more info but the modal doesn't want to show the image, pretty new to vue and such so I have no clue what's wrong:
<div class="container" id="app">
<div class="row justify-content-center mt-5">
<div class="card mr-5 mb-5" v-for="product in products" v-bind:key="product.id">
<div class="card-body">
<img v-bind:src="product.image" style="height:15rem">
<h5 class="card-title">{{ product.name }}</h5>
<p class="card-text">{{ product.description }}</p>
<p class="card-text"><b>Price: {{ product.price }}</b></p>
<button type="button" class="btn btn-primary" data-toggle="modal"
v-on:click="showProductInUpdateForm(product.id)">More Info</button>
</div>
</div>
</div>
<div class="modal fade" id="updateModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">More Info</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form id="formUpdate">
<img v-bind:src="product.image">
<div class="form-group">
<label for="Id">ID</label>
<input type="text" class="form-control" name="updateId" id="updateId" readonly>
</div>
<div class="form-group">
<label for="Name">Name</label>
<input type="text" class="form-control" name="updateName" id="updateName" readonly>
</div>
<div class="form-group">
<label for="Description">Description</label>
<input type="text" class="form-control" name="updateDescription" id="updateDescription" readonly>
</div>
<div class="form-group">
<label for="Price">Price</label>
<input type="text" class="form-control" name="updatePrice" id="updatePrice" readonly>
</div>
<div class="form-group">
<label for="Image">Image</label>
<input type="text" class="form-control" name="updateImage" id="updateImage" readonly>
</div>
<div class="form-group">
<button type="submit" class="btn btn-danger float-right" data-dismiss="modal">Close</button>
<button type="button" class="add-to-cart btn btn-primary float-right" data-dismiss="modal">Add to cart</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>

You are declaring variable product in a v-for loop. So product can be only accessed inside that loop block.
<div v-for="product in products" v-bind:key="product.id">
{{product}}
</div>
...
<!-- product is 'undefined' here since it's outside of the v-for loop block -->
<img v-bind:src="product.image">
You can store selected item in some global property that can be accessed from everywhere:
<button v-on:click="showProductInUpdateForm(product)">More Info</button>
...
<img v-bind:src="selectedItem.image">
data {
return {
selectedItem: {}
}
},
methods: {
showProductInUpdateForm (product) {
this.selectedItem = product
...
}
}

Related

Datetimepicker box keeps changing the size

I have a bootstrap datetimepicker in my form. But when i select datetime, input box size keeps changing. After input it, i can't change the datetime with datetimepicker. I think, it's because datatble.min.js conflict with datetimepicker.js. But, but i still haven't solved it. Any help would be appreciated.
Before
Before add datetimepicker
Add
Add Date
Add Time
After
Input box size changed
Modal
<div id="modal_form" class="modal fade" role="dialog" aria-hidden="true" aria labelledby="formModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="formModalLabel"></h4>
</div>
<div class="modal-body">
<form class="form-horizontal" id="form" role="form" action="<?= base_url("catalog/insert") ?>" method="POST" enctype="multipart/form-data">
<div class="form-group">
<label class="col-md-3 control-label">Start Date</label>
<div class="col-md-9">
<div class="input-group date form_datetime form_datetime bs-datetime">
<input type="text" size="16" class="form-control" name="start">
<span class=" input-group-addon">
<button class="btn default date-set" type="button">
<i class="fa fa-calendar"></i>
</button>
</span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">End Date</label>
<div class="col-md-9">
<div class="input-group date form_datetime form_datetime bs-datetime">
<input type="text" size="16" class="form-control" name="end">
<span class="input-group-addon">
<button class="btn default date-set" type="button">
<i class="fa fa-calendar"></i>
</button>
</span>
</div>
</div>
</div>
<div class="form-group">
<label class="col-md-3 control-label">Descirption</label>
<div class="col-md-9">
<textarea class="form-control" rows="3" name="desc" id="desc" val=""></textarea>
<span class="help-block"></span>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn grey-salsa btn-outline" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button class="btn green btn-primary" data-dismiss="modal" type="submit" id="btnsave">Save</button>
</div>
</div>
</div>
</div>
I suggest you use some special libraries which are made for this. https://www.daterangepicker.com/
https://flatlogic.com/blog/best-javascript-datepicker-libraries/

Angular - How to style my form to accomodate all the field data

I am working on an application using Angular-7 frontend. In the form that is shown below, the form field elements are truncated and not everything is displayed:
addModal
<div id="addModal" class="modal" style="background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4);">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add New Role</h5>
<button type="button" class="close" (click)='closeAddModal()'>
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="alert alert-danger" [hidden]="!error.name">
{{ error.name }}
</div>
<form #editRoleForm=ngForm>
<div class="form-group">
<label for="name">Name</label>
<input type="name" name="name" id="inputName" class="form-control" placeholder="Name" [(ngModel)]="form.name" required>
</div>
<div class="form-group">
<label for="name">Permissions</label>
<div *ngFor="let permission of permissions">
<input type="checkbox" name="{{ permission.name }}" value="{{ permission.name }}" (change)="checkboxAdd($event)"> {{ permission.name }}
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" (click)='addModalSubmit()' [disabled]="!editRoleForm.valid">Save changes</button>
<button type="button" class="btn btn-secondary" (click)='closeAddModal()'>Close</button>
</div>
</div>
</div>
</div>
editModal
<div id="editModal" class="modal" style="background-color: rgb(0,0,0); background-color: rgba(0,0,0,0.4);">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit Role</h5>
<button type="button" class="close" (click)='closeEditModal()'>
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="alert alert-danger" [hidden]="!error.name">
{{ error.name }}
</div>
<form #newRoleForm=ngForm>
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required [(ngModel)]="data.name"/>
</div>
<div class="form-group">
<label for="name">Permissions</label>
<div *ngFor="let permission of permissions">
<input type="checkbox" name="{{ permission.name }}" value="{{ permission.name }}" (change)="checkbox($event)" *ngIf="!data.permission.includes(permission.name)">
<input type="checkbox" name="{{ permission.name }}" value="{{ permission.name }}" (change)="checkbox($event)" *ngIf="data.permission.includes(permission.name)" checked> {{ permission.name }}
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-primary" [disabled]="!newRoleForm.valid" (click)='editsubmit()'>Save changes</button>
<button type="button" class="btn btn-secondary" (click)='closeEditModal()'>Close</button>
</div>
</div>
</div>
</div>
How do I style the form, so that all the form elements will be displayed (I can't even see the submit button)? It may even be in three columns.

form.valid on Angular gets false after the 1st submit

I am working on Angular 7 and having the following situation:
.html code (updated):
<form #form="ngForm" (ngSubmit)="addRecord(form)">
<div class="modal-header">
<h5 class="modal-title" id="modalRecordLabel">Add Record</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close" (click)="resetForm(form)">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<small style="margin-top: 10px;">All fields with asterisk (*) are required.</small>
<div class="container-fluid">
<div class="row">
<div class="col-md-10">
<!-- Name -->
<div class="form-group">
<label for="input1">Name *</label>
<input
type="text"
class="form-control"
id="input1"
name="input1"
[(ngModel)]="myObject.description"
required
#input1=ngModel
[class.field-error]="form.submitted && input1.invalid"
tabindex="11">
<div [hidden]="!form.submitted || input1.valid " class="alert alert-danger">
Name is required.
</div>
</div>
<!-- Date 1-->
<div class="form-group">
<label for="date1">Date 1 *</label>
<div class="input-group">
<input
class="form-control"
placeholder="yyyy-mm-dd"
id="date1"
name="date1"
[ngModel]="date1"
required
#date1=ngModel
[class.field-error]="form.submitted && date1.invalid"
ngbDatepicker #da="ngbDatepicker"
tabindex="12">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="da.toggle()" type="button"></button>
</div>
</div>
<div [hidden]="!form.submitted || date1.valid " class="alert alert-danger">
Date 1 is required.
</div>
</div>
<!-- Date 2 -->
<div class="form-group">
<label for="date2">Date 2 *</label>
<div class="input-group">
<input
class="form-control"
placeholder="yyyy-mm-dd"
id="date2"
name="date2"
[ngModel]="date2"
required
#date2=ngModel
[class.field-error]="form.submitted && date2.invalid"
ngbDatepicker #da2="ngbDatepicker"
tabindex="13">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="da2.toggle()" type="button"></button>
</div>
</div>
<div [hidden]="!form.submitted || date2.valid " class="alert alert-danger">
Date 2 is required.
</div>
</div>
<!--Date 3-->
<div class="form-group">
<label for="date3">Date 3</label>
<div class="input-group">
<input
class="form-control"
placeholder="yyyy-mm-dd"
id="date3"
name="date3"
[ngModel]="date3"
ngbDatepicker #da3="ngbDatepicker"
tabindex="14">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="da3.toggle()" type="button"></button>
</div>
</div>
</div>
<!--Date 4-->
<div class="form-group">
<label for="date4">Date 4</label>
<div class="input-group">
<input
class="form-control"
placeholder="yyyy-mm-dd"
id="date4"
name="date4"
[ngModel]="date4"
ngbDatepicker #da4="ngbDatepicker"
tabindex="15">
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="da4.toggle()" type="button"></button>
</div>
</div>
</div>
<!-- Type -->
<div class="form-group">
<label for="input2">Type</label>
<div class="input-group">
<select
class="form-control"
id="input2"
name="input2"
[(ngModel)]="myObject.type.id"
(change)="selectOption($event.target.value)"
#input2="ngModel"
tabindex="16">
<option *ngFor='let input2 of input2List' [value]="input2.id">{{input2.description}}</option>
</select>
</div>
</div>
</div>
</div>
</div> <!-- closing div for class="container-fluid"-->
</div> <!-- closing div for class="modal-body"-->
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="resetForm(form)" tabindex="101">Close</button>
<button type="submit" class="btn btn-primary" tabindex="102">Add</button>
</div>
</form>
.ts code:
addRecord(form: NgForm): void {
if(form.valid) {
//do something
}
}
The first time the form is submitted, all the data is saved successfully. However, if I tried to submit a second record using the same form, now form.valid is always false.
So my question is, why is form.valid always false after the first submit?

Element with name not being sent with form data via POST

I am trying to submit my modal title as post data, however it isn't being sent.
I have given the element a name attribute. Elements in the modal body are submitting as I would expect. Trying to submit the element whose name is "editModalTitle" below
HTML:
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<form action="/editItem" method="post" id ="editModalForm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" name="eModalTitle"></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Quantity:</label>
<div class="row">
<div class="col">
<select class="form-control" id="qtSelect">
<option>Set to</option>
<option>Add</option>
<option>Subtract</option>
</select>
</div>
<div class="col" id= "qtD">
<input type="text" class="form-control" id="qt" name="quantityTB" placeholder="Quantity">
</div>
</div>
</div>
<div class="form-group" id="prD">
<label>Price:</label>
<input type="text" class="form-control" id="pr" name="priceTB" placeholder="Enter new price here...">
</div>
<div class="form-group">
<label>Notes:</label>
<div class="row">
<div class="col">
<select class="form-control" id="ntSelect">
<option>Set notes to:</option>
<option>Add to notes:</option>
</select>
</div>
<div class="col">
<input type="text" class="form-control" id="ntInput" name="notesTB"placeholder="Enter notes here...">
</div>
</div>
</div>
<div class="form-group">
<label>Location:</label>
<input type="text" class="form-control" id="loc" name="locationTB" placeholder="Enter new location here...">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" id="eSvBtn" class="btn btn-primary">Save changes</button>
</div>
</form>
</div>
</div>
</div>
</div>
Form data here
Edit 1: Added full html for modal.
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModal" aria-hidden="true">
<div class="modal-dialog" role="document">
<form action="/editItem" method="post" id ="editModalForm">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" name="eModalTitle"></h5>
<!-- hidden value for modal title to post -->
<input type="hidden" id="Modal_title_to_post" name="Modal_title_to_post" value="eModalTitle">
<!-- hidden value for modal title to post -->
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<label>Quantity:</label>
<div class="row">
<div class="col">
<select class="form-control" id="qtSelect">
<option>Set to</option>
<option>Add</option>
<option>Subtract</option>
</select>
</div>
<div class="col" id= "qtD">
<input type="text" class="form-control" id="qt" name="quantityTB" placeholder="Quantity">
</div>
</div>
</div>
<div class="form-group" id="prD">
<label>Price:</label>
<input type="text" class="form-control" id="pr" name="priceTB" placeholder="Enter new price here...">
</div>
<div class="form-group">
<label>Notes:</label>
<div class="row">
<div class="col">
<select class="form-control" id="ntSelect">
<option>Set notes to:</option>
<option>Add to notes:</option>
</select>
</div>
<div class="col">
<input type="text" class="form-control" id="ntInput" name="notesTB"placeholder="Enter notes here...">
</div>
</div>
</div>
<div class="form-group">
<label>Location:</label>
<input type="text" class="form-control" id="loc" name="locationTB" placeholder="Enter new location here...">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="submit" id="eSvBtn" class="btn btn-primary">Save changes</button>
</div>
</div>
</form>
</div>
</div>
Updated code with hidden value for the modal title :)

Angular-strap's aside overlaps whole page

I'm using angular-strap aside with Bootstrap3. My aside html template is given below -
<div class="aside" tabindex="-1" role="dialog">
<div class="aside-dialog">
<div class="aside-content">
<div class="aside-header">
<button type="button" class="close" ng-click="$hide()">×</button>
<h4 class="aside-title">Settings</h4>
</div>
<div class="aside-body" ng-controller="SettingsCtrl">
<form name="createCustomerForm" role="form">
<div class="form-group">
<label for="settings_email">Email</label>
<input class="form-control" id="settings_email" name="settings_email" type="text">
</div>
<div class="form-group">
<label for="language">Language: </label>
<button id="language" type="button" class="btn btn-default" data-html="1"
data-animation="am-flip-x" ng-options="country.name for country in countries track by country.id"
data-placeholder="Select country..."
ng-model="selectedLang" ng-change="onLanguageSelected(country)"
bs-select>
Action <span class="caret"></span>
</button>
</div>
</form>
</div>
<div class="aside-footer">
<button type="button" class="btn btn-default" ng-click="$hide()">Close</button>
</div>
</div>
</div>
</div>
This works so far-
But if I change the code -
<div class="aside" tabindex="-1" role="dialog">
<div class="aside-dialog">
<div class="aside-content">
<div class="aside-header">
<button type="button" class="close" ng-click="$hide()">×</button>
<h4 class="aside-title">Settings</h4>
</div>
<div class="aside-body" ng-controller="SettingsCtrl">
<form name="createCustomerForm" role="form">
<div class="form-group">
<label for="settings_email">Email</label>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-envelope-o fa-fw"></i></span>
<input class="form-control" id="settings_email" name="settings_email" type="text">
</div>
</div>
<div class="form-group">
<label for="language">Language: </label>
<button id="language" type="button" class="btn btn-default" data-html="1"
data-animation="am-flip-x" ng-options="country.name for country in countries track by country.id"
data-placeholder="Select country..."
ng-model="selectedLang" ng-change="onLanguageSelected(country)"
bs-select>
Action <span class="caret"></span>
</button>
</div>
</form>
</div>
<div class="aside-footer">
<button type="button" class="btn btn-default" ng-click="$hide()">Close</button>
</div>
</div>
</div>
</div>
Then it captures the whole window -
How can I make it to remain same size?
You can just add a max-width tag on your content class in aside template that you are loading.
Assume