Edit an input text in Angular - html

I have a form in Angular with an input type text that I need to be able to edit by hitting the edit button.
I have 3 buttons, edit, cancel the change and save the change.
If the edit button is pressed, the input is enabled to be able to modify it, the edit button is hidden and the save and cancel buttons are shown.
If the cancel button is pressed, the change is canceled and the text that was initially displayed is shown and only the edit button is shown.
If the save button is pressed, the current changes are saved and replaced by the previous information, and only the edit field is shown again.
This is my html with a single input:
<input type="text" id="name" name="name" required
minlength="4" maxlength="8" size="10">
<button class="btn"><i class="fa fa-pencil"></i></button>
<button class="btn"><i class="fa fa-close"></i></button>
<button class="btn"><i class="fa fa-save"></i></button>
How can I get this behavior on the page? What functions should I add in component.ts?

Have toedit = true in ur *.ts file
<div class="row g-0">
<div *ngIf="!toedit">
<label for=""> {{dataNew}} </label>
<div class="float-end">
<label><i class="fas fa-pencil p-1" (click)="toedit=!toedit"></i></label>
<label><i class="fas fa-minus-circle p-1" (click)="removeLabel(k)"></i></label>
</div>
</div>
</div>
<div class="row" *ngIf="toedit">
<div class="col-10 align-self-center">
<input type="text"/>
</div>
<div class="col-1 ms-1 align-self-center">
<label><i class="fas fa-check" [(ngModal)] = "dataNew" (click)="updateLabel(dataNew)"></i></label>
</div>
</div>
Have a try on this

Related

JQUERY: identify submit button from <div class="form">

How can I determine which submit button was clicked?
I do not want to use <form>, because the page refreshes. By clicking the submit button, a PHP-file gives back a response that is shown on the current page.
HTML in index.html:
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
</head>
<body>
[...]
<div class="form-inline" id="form">
<div class="container">
<div class="form-group">
<div class="input-group input-group-sm">
<div class="input-group-text regwidth">
First name
</div>
<input type="text" class="form-control" name="registerFirstname" id="firstname">
</div>
<div class="input-group input-group-sm">
<div class="input-group-text regwidth">
Last name
</div>
<input type="text" class="form-control" name="registerLastname" id="lastname">
</div>
<div class="d-grid gap-2 col-8 mx-auto">
<button type="submit" class="btn btn-primary" id="sublogreg"><i class="fa-solid fa-address-card"></i> Register</button>
<button type="submit" class="btn btn-primary" id="subloginfo"><i class="fa-solid fa-circle-info"></i> Request information</button>
<p id="returnmessage"></p>
</div>
[...]
jQuery script in index.html:
<script>
$("#form").ready(function() {
$("#sublogreg,#subloginfo").click(function() {
var firstname = $("#firstname").val();
var lastname = $("#lastname").val();
var sublogreg = $("#sublogreg").val();
var subloginfo = $("#subloginfo").val();
[...]
I tried to add
value="sublogreg"
in the <button>. The value is set, but then both submit button has their value.
I am an autodidact searching for solutions if I need something. I am not a specialist.
You can detect the button you click in several ways, but one simple solution is to add data-id="whatever_choose_id" in each button. The data-id should be different for each button eg
<button type="submit" class="btn btn-primary" data-id="firstBtn" id="subloginfo">
<i class="fa-solid fa-circle-info"></i>
Request information
</button>
<button type="submit" class="btn btn-primary" data-id="secondBtn" id="subloginfo">
<i class="fa-solid fa-circle-info"></i>
Request information
</button>
Then to access it in jQuery you use let btnID = $(this).data("id");
btnID will be the id of the button you clicked

Bootstrap 4 .form-inline not working in Internet Explorer 11

I have a form in an application using Bootstrap 4. It renders as I want it to in all browsers, except Internet Explorer 11.
I have used Bootstrap's .form-inline class because according to the docs
Use the .form-inline class to display a series of labels, form controls, and buttons on a single horizontal row.
The correct rendering of the form looks like this. The screenshot below was taken from Chrome v80:
In Internet Explorer 11 it renders as follows.
The markup is as follows.
<div class="row">
<form method="get" class="form-inline" action="#">
<div class="col">
<label for="date_start" class="mr-2 float-left">From</label>
<div class="input-group date mr-5" id="dateStart" data-target-input="nearest">
<div class="input-group-append" data-target="#dateStart" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar" aria-hidden="true"></i></div>
</div>
<input type="text" name="dateStart" value="2020-03-17" class="form-control datetimepicker-input" data-target="#dateStart" autocomplete="off">
</div>
</div>
<div class="col">
<label for="date_end" class="mr-2 float-left">To</label>
<div class="input-group date mr-5" id="dateEnd" data-target-input="nearest">
<div class="input-group-append" data-target="#dateEnd" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar" aria-hidden="true"></i></div>
</div>
<input type="text" name="dateEnd" value="2020-03-24" class="form-control datetimepicker-input" data-target="#dateEnd" autocomplete="off">
</div>
</div>
<button class="btn btn-primary btn-md-top-pad">View Notifications <i class="fas fa-chevron-right" aria-hidden="true"></i></button>
</form>
</div>
If I remove the .form-inline in Internet Explorer 11 using Developer Tools the layout is more usable but still broken.
I read inline-flex input element breaks to new line in IE11 and tried swapping my .row with a .container. This seems to help but it centres the form and therefore doesn't look as I want in other (non IE 11) browsers. It also makes the input fields look much longer than desired.
Surely it is possible to left align the form and have it all on one line?
What is the problem with this and how can I fix it for IE 11 in a way that won't break it for other browsers? I want to render it as per the first screenshot, consistently in all browsers.
I compared with the official demo which can work well in IE 11, it seems that the issue is with <div class="col">. The elements in the form are not wrapped by div .col in the official demo. I removed them and it can work well in IE 11 and other browsers.
Online demo
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" />
<form method="get" class="form-inline" action="#">
<label for="date_start" class="mr-2 float-left">From</label>
<div class="input-group date mr-5" id="dateStart" data-target-input="nearest">
<div class="input-group-append" data-target="#dateStart" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar" aria-hidden="true"></i></div>
</div>
<input type="text" name="dateStart" value="2020-03-17" class="form-control datetimepicker-input" data-target="#dateStart" autocomplete="off">
</div>
<label for="date_end" class="mr-2 float-left">To</label>
<div class="input-group date mr-5" id="dateEnd" data-target-input="nearest">
<div class="input-group-append" data-target="#dateEnd" data-toggle="datetimepicker">
<div class="input-group-text"><i class="fa fa-calendar" aria-hidden="true"></i></div>
</div>
<input type="text" name="dateEnd" value="2020-03-24" class="form-control datetimepicker-input" data-target="#dateEnd" autocomplete="off">
</div>
<button class="btn btn-primary btn-md-top-pad">View Notifications <i class="fas fa-chevron-right" aria-hidden="true"></i></button>
</form>

How can i set choose profile image input on right side of input with label instead of "choose file" ->'choose image'

i am creating teacher form i want to choose images from gallery for profile , i want to change label and position of "choose image button " on the right side with label of "Choose Image" & label in same input box on left side "please select profile picture " i am using angular and bootstrap 4
This is html
<div class="form-group ">
<p class="input-group">
<i class="fa fa-camera fa-2x user-icon fa-fw" aria-hidden="true"></i>
<label for="file">Choose file to upload</label>
<input type="file" name="pic" accept="image/* " class="form-control">
</p>
</div>
This is Css.
.form-control{
background: #000;
color: beige;
}
<div class="form-group ">
<p class="input-group">
<i class="fa fa-camera fa-2x user-icon fa-fw" aria-hidden="true"></i>
<label for="file" class="col-sm-10 form-control">Choose file to upload</label>
<input type="file" name="pic" accept="image/* " class="col-sm-2 form-control">
</p>
</div>
Please try this way. Hope this will help you.. :)

Im still able to select any file after declaring to only accept image files in an input

Here is my form:
<form #optionsForm="ngForm" novalidate (ngSubmit)="saveOptions()" id="optionsForm">
<div class="modal-body">
<div class="form-group">
<label for="customFile">Icon</label>
<div class="custom-file">
<input type="file" accept="image/*" class="custom-file-input" id="customFile"
name="customerFile" (change)="handleFileInput($event.target.files)" required>
<label class="custom-file-label" for="customFile"
id="customerFileLabel">Select Icon</label>
</div>
</div>
<div *ngIf="logo.imageInBase64" class="row">
<label id="previewLabel">Preview:</label>
<div class="report-logo">
<img alt="{{logo.name}}" src="{{logo.imageInBase64}}" class="logo-image">
</div>
</div>
<button type="submit" class="btn btn-secondary" aria-hidden="true"
[disabled]="!optionsForm.valid">
<i class="fa fa-floppy-o"></i> Save
</button>
</div>
</form>
Thats how it looks without and with a file selected:
I have two problems currently. Firstly i tried to define with accept="image/* that only images should be accepted by the input. But the only thing it does is opening the file manager with a image filter, but im still able to switch to all files and select a non image file. Is there a way to avoid that?
The second problem is the formvalidation. I disable the button if the form is invalid with [disabled]="!optionsForm.valid".I put the required attribte to the input, so that should invalidate the form and disable the button if no input is selected, but it currently is not doing that. The form is still valid even if i did not select any file.
You can also specify extension with the image as shown below. This will allow only a specified extension for file selection and upload. I hope this works for you.
<form #optionsForm="ngForm" novalidate (ngSubmit)="saveOptions()" id="optionsForm">
<div class="modal-body">
<div class="form-group">
<label for="customFile">Icon</label>
<div class="custom-file">
<input type="file" accept="image/x-png,image/gif,image/jpeg" class="custom-file-input" id="customFile"
name="customerFile" (change)="handleFileInput($event.target.files)" required>
<label class="custom-file-label" for="customFile"
id="customerFileLabel">Select Icon</label>
</div>
</div>
<div *ngIf="logo.imageInBase64" class="row">
<label id="previewLabel">Preview:</label>
<div class="report-logo">
<img alt="{{logo.name}}" src="{{logo.imageInBase64}}" class="logo-image">
</div>
</div>
<button type="submit" class="btn btn-secondary" aria-hidden="true"
[disabled]="!optionsForm.valid">
<i class="fa fa-floppy-o"></i> Save
</button>
</div>
</form>

positioning my button near the text box for an html document

i need help in getting my seach button near my text box it seems to come below the text box
program:
<div class="search-full text-right">
<a class="pull-right search-close"><i class=" fa fa-times-circle"></i></a>
<div class="searchInputBox pull-right">
<input type="search"
data-searchurl="search?="
name="q"
placeholder="start typing and hit enter to search"
class="search-input">
<button class="btn-nobg search-btn" type="submit">
<i class="fa fa-search"> </i>
</button>
</div>
</div>
As per Bootstrap standard, using an input-group is the best bet.
See: http://getbootstrap.com/components/#input-groups-buttons
Bootply Example using some of your code
HTML:
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<input type="search"
data-searchurl="search?="
name="q"
placeholder="start typing and hit enter to search"
class="search-input form-control">
<span class="input-group-btn">
<button class="btn search-btn" type="submit">
<i class="glyphicon glyphicon-search"> </i>
</button>
</span>
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div>
EDIT: I've also created a Bootply fork with the 'clear' button for you, though it's slightly hacked. See Bootply