How to customize input field length in AngularJS? - angularjs

I have 4 input fields and type of each field is number. I have implemented it as follows
<div class="row ml-3 mr-3 mt-3">
<div class="column mr-3">
<label class="col-form-label">
Available Amount : <br/><input type="number"
class="mr-3"
[(ngModel)]="selectedItemAvailability"
[disabled]="true">
</label>
</div>
<div class="column ml-5">
<label class="col-form-label">
Enter Quantity : <br/><input type="number"
[min]="1"
[max]="selectedItemAvailability"
[(ngModel)]="selectedItemQuantity">
</label>
</div>
</div>
<div class="row ml-3 mr-3 mt-3">
<div class="column mr-3">
<label class="col-form-label">
Price : <br/><input type="number"
[min]="0"
class="mr-3"
[(ngModel)]="selectedItemPrice">
</label>
</div>
<div class="column ml-5">
<label class="col-form-label">
Item Discount : <br/><input type="number"
[min]="0"
[max]="100"
class="mr-3"
[(ngModel)]="selectedItemDiscount">
</label>
</div>
</div>
Once the program is executed, it gives me the interface as below,
When I use input type as text, it gives the expected output.
I want to make all the input fields same in length while using the input type as number. How can I achieve this?
Expected Output:

It seems your code works perfect. Please check stackblitz for the detail:
https://stackblitz.com/edit/angular-ivy-b7xnya?file=src/app/app.component.html
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.css" rel="stylesheet"/>
<div class="row ml-3 mr-3 mt-3">
<div class="column mr-3">
<label class="col-form-label">
Available Amount : <br /><input type="number" class="mr-3">
</label>
</div>
<div class="column ml-5">
<label class="col-form-label">
Enter Quantity : <br /><input type="number">
</label>
</div>
</div>
<div class="row ml-3 mr-3 mt-3">
<div class="column mr-3">
<label class="col-form-label">
Price : <br /><input type="number" [min]="0" class="mr-3">
</label>
</div>
<div class="column ml-5">
<label class="col-form-label">
Item Discount : <br /><input type="number" class="mr-3">
</label>
</div>
</div>

Related

angularjs radio button defaut value not selected

I have a radio button which works fine if I remove Angularjs but if I added the Angularjs code it doesn't have a default selected/checked value.
I have the same ng-model="frm.mode" but still nothing is selected by default.
HTML
<div class="border-bottom border-color-1 border-dotted-bottom">
<div class="p-3" id="basicsHeadingThree">
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" id="thirdstylishRadio1" ng-model="frm.mode" value="DELIVERY" name="mode" checked>
<label class="custom-control-label form-label" for="thirdstylishRadio1"
data-toggle="collapse"
data-target="#basicsCollapseThree"
aria-expanded="false"
aria-controls="basicsCollapseThree">
Delivery
</label>
</div>
</div>
<div id="basicsCollapseThree" class="collapse show border-top border-color-1 border-dotted-top bg-dark-lighter"
aria-labelledby="basicsHeadingThree"
data-parent="#basicsAccordion1">
<div class="p-4">
cash on delivery
</div>
</div>
</div>
<!-- End Card -->
<!-- Card -->
<div class="border-bottom border-color-1 border-dotted-bottom">
<div class="p-3" id="basicsHeadingOne">
<div class="custom-control custom-radio">
<input type="radio" class="custom-control-input" id="stylishRadio1" ng-model="frm.mode" value="PICKUP" name="mode">
<label class="custom-control-label form-label" for="stylishRadio1"
data-toggle="collapse"
data-target="#basicsCollapseOnee"
aria-expanded="true"
aria-controls="basicsCollapseOnee">
Pickup
</label>
</div>
</div>
<div id="basicsCollapseOnee" class="collapse border-top border-color-1 border-dotted-top bg-dark-lighter"
aria-labelledby="basicsHeadingOne"
data-parent="#basicsAccordion1">
<div class="p-4">
pickup order
</div>
</div>
</div>

Unable to get the value using getAttribute method,and Javascript in selenium

the element marked i want to get the value to compare it with excel data
#FindBy(id="TAXEI")
//#FindBy(xpath="//*[#id='TAXEI']")
public WebElement taxesEIvalue;
public void verifyTaxesEIvalue() {
//jse.executeScript("arguments[0].setAttribute('type', '')",taxesEIvalue);
String value=taxesEIvalue.getAttribute("value");
System.out.println("the value is "+value);
}
I am facing problem to get the value in an application to compare it from excel,but unable to get value through Dom structure.The Html structure did't provide Value attribute
Here is the html code for the element unable to get the value that is in text box,i have compare with that value with the excel data using data driven
<div class="col-lg-6 col-md-6 col-sm-6">
<fieldset class="fsStyle">
<legend class="legendStyle">
<label class="control-label main">TAXES</label>
</legend>
<div class="wages">
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">EI</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXEI" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">QPIP</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXQPIP" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">CPP</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXCPP" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">QPP</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXQPP" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">Income Tax</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXIT" disabled="disabled">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-5">
<label class="control-label">Quebec Tax</label>
</div>
<div class="col-sm-7">
<input type="text" class="control-label TAX pull-right" id="TAXQTax" disabled="disabled">
</div>
</div>
</div>
<a id="divExemptNamesIncome"></a>
<p class="form-control-static"><strong id="divExemptNamesIncome"></strong></p>
</div>
</fieldset>
</div>

Not able to add validations to the elements in my form

I want to add validations to all the elements in the form. the error message should be displayed below the elements when the text of the control changes.
Following is my code:
<div role="tabpanel" class="tab-pane active" id="step-1">
<div class="col-md-4">
<div> <img src="../logo.jpg"
alt="Smiley face"
height="150"
style="margin:40px;"
width="150">
</div>
</div>
<div class="col-md-7">
<form action="r" name="regform"
method="post" >
<div class="col-md-6">
<div class="col-md-6" style="padding:0px;" >
<label for="mType" >Member Type*</label> <br />
<select id="member" ng-model="inputForm.mType" style="height:35px;width:135px;">
<option value="owner">Owner</option>
<option value="agent">Agent</option>
<option value="agent">Customer</option>
</select>
</div>
<div class="form-group">
<div class="col-md-6" style="padding:0px;" >
<label for="gender" >Gender </label> <br />
<select id="gender" ng-model="inputForm.gender" style="height:35px;width:135px;">
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</div>
</div>
<div class="form-group">
<label for=''>First Name</label>
<input type='name'
name='fName'
ng-model="inputForm.fName"
ng-minlength="1"
ng-maxlength="25"
ng-pattern="/^[A-Za-z]+$/"
required
/>
<span ng-show="regform.fName.$error.pattern">Please enter valid number!</span>
<!-- <span ng-show="studentForm.firstName.$touched && studentForm.firstName.$error.required">First name is required.</span>
<span ng-show="studentForm.lastName.$touched && studentForm.lastName.$error.minlength">min 3 chars.</span>
<span ng-show="studentForm.lastName.$touched && studentForm.lastName.$error.maxlength">Max 10 chars.</span>-->
</div>
<div class="form-group">
<label>Last Name : </label>
<input type="text"
name="lName"
class="form-control input-lg"
placeholder="Last Name"
ng-model="inputForm.lName"
style="height:35px">
</input>
</div>
<div class="form-group">
<label for="DOB">Date of Birth :</label>
<input type="date"
id="dob"
class="form-control input-lg"
placeholder="Date Of Birth (mm/dd/yyyy)"
ng-model="inputForm.dob"
style="height:35px;">
</input>
</div>
<div class="form-group">
<label>Adhar Number:</label>
<input type="text" id="adhar"
class="form-control input-lg"
placeholder="Adhar Number"
ng-model="inputForm.adhar"
style="height:35px">
</input>
</div>
<div class="form-group">
<label>PAN Number :</label>
<input type="text" id="pan"
class="form-control input-lg"
placeholder="PAN Number"
ng-model="inputForm.pan"
style="height:35px">
</input>
</div>
<div class="form-group">
<label>Email Address :</label>
<input type="email" id="email"
class="form-control input-lg"
placeholder="Your Email"
ng-model="inputForm.email"
style="height:35px">
</input>
<!-- <span ng-show="studentForm.email.$touched && studentForm.email.$error.email">Please enter valid email id.</span>-->
</div>
</div>
<div class="col-md-5" >
<div class="full-width bg-transparent">
<div class="full-width">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="custom-form">
<div class="text-center bg-form">
<div class="img-section">
<img src="http://lorempixel.com/200/200/nature/"
class="imgCircle"
alt="Profile picture">
<span class="fake-icon-edit"
id="PicUpload"
style="color: #ffffff;">
<span class="glyphicon glyphicon-camera camera"></span>
</span>
<div class="col-lg-12">
<h4 class="text-right col-lg-12" style="color:balck;">
<span class="glyphicon glyphicon-edit"></span> Edit Profile
</h4>
<input type="checkbox" class="form-control" id="checker"></input>
</div>
</div>
<input type="file"
id="image-input"
onchange="readURL(this);"
accept="image/*"
disabled class="form-control form-input Profile-input-file" >
</input>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-8" >
<hr class="colorgraph" style="height: 5px;
border-top: 0;
background: #62c2e4;
border-radius: 5px;">
<div class="col-xs-4 col-xs-offset-3">
<a ui-sref="form.account" class="btn btn-lg btn-primary btn-block signup-btn"
style=" height:35px;
margin-bottom:10px;
padding:0px;" >
Next <span class="glyphicon glyphicon-circle-arrow-right"></span>
</a>
</div>
</div>
</form>
</div>
</div>
image for reference
Please give suggestions to change the code so that appropriate error messages will be displayed to the controls after validating the input entr the user.
Your question is a bit vague as we can do what you are asking in many ways but find below an example using Bootstrap :
<form name="search" class="form-horizontal">
<div class="form-group col-md-2 required" ng-class="{
'has-feedback': (search.$submitted && search.carrier.$invalid),
'has-error': (search.$submitted && search.carrier.$invalid)}">
<label class="control-label" for="carrier">Carrier Code:</label>
<input type="text" class="form-control"
id="carrier" name="carrier"
required
pattern="[a-zA-Z0-9-]{2,3}"
maxlength="3"
ng-model="myAngularCtrl.flightDetails.carrier"/>
<span ng-show="search.$submitted && search.carrier.$error.required" class="field_errormsg-below">The Carrier Code is Mandatory</span>
<span ng-show="search.$submitted && search.carrier.$error.pattern" class="field_errormsg-below">use only numbers, digit and -</span>
</div>
<button type="submit"
class="btn btn-default FHU_margin-top-20"
ng-click="myAngularCtrl.searchFlight(search)">
Submit
</button>
</form>
You have a few things here:
The form has a name: search
You see two kind of error message being displayed. For them to be displayed, the user needs to have tried to submit the form (search.$submitted) and the field carrier needs to be in error (search.carrier.$error.required or search.carrier.$error.pattern)

Angularjs IF - ELSE condtion on checkboxes

i am new to Angular js i want to ask i have a case in which i have to return "YES" if the checkbox is checked or true and want to return "NO" when the value is false or unchecked.
actually my data is storing in databse in "Tinyint" 1 or 0 form i want to do when 1 occurs it shows YES any solution for this Any help will be appreciated.
Here is my html
<form class="form-horizontal">
<div class="form-group">
<label class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" ng-model="rec.Name" placeholder="Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox c-checkbox">
<label>
<input type="checkbox" value="" ng-model="rec.isSpecial">
<span class="fa fa-check"></span>is Special</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox c-checkbox">
<label>
<input type="checkbox" ng-model="rec.isMultiple">
<span class="fa fa-check"></span>Is Multiple</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="button" ng-click="add(rec)" class="btn btn-sm btn-primary">ADD</button>
</div>
</div>
</form>
i need to target checkbox ismultiple and isspecial .
You can use ng-true-value of ng-false-value like this:
<form class="form-horizontal">
<div class="form-group">
<label class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" ng-model="rec.Name" placeholder="Name" class="form-control">
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox c-checkbox">
<label>
<input type="checkbox" ng-model="rec.isSpecial" ng-true-value = "YES" ng-false-value="NO">
<span class="fa fa-check"></span>is Special</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<div class="checkbox c-checkbox">
<label>
<input type="checkbox" ng-model="rec.isMultiple" ng-true-value = "YES" ng-false-value="NO">
<span class="fa fa-check"></span>Is Multiple</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="button" ng-click="add(rec)" class="btn btn-sm btn-primary">ADD</button>
</div>
</div>
</form>

ng-disable tab/button when content in previous tab has not completed

I make a tab panel and declare it as form type, then i put validation ng-disabled in button& tab. i want the button available after i finish fill up two form,my button is disabled at first but when i finish fill up "first" form then it able to clicked. And also tab, it never disabled...
<div class="panel-body">
<form class="tab-content form-horizontal"name="formData" novalidate>
<div id="form-views" ui-view></div>
</form>
here my code:
button
<button type="button" ng-click="addPost()"
ngdisabled="formData.$invalid" class="btn btn-success">Submit
</button>
tab
<div class="col-lg-12 col-sm-12">
<div class="row">
<div class="col-lg-8 col-sm-8">
<div class="panel panel-tab rounded shadow">
<div class="panel-heading1 no-padding">
<ul class="nav nav-tabs nav-pills">
<li class="active" ui-sref=".personal" >
<a data-toggle="tab">
<i class="fa fa-user"></i>
<div>
<span class="text-strong">Step 1</span>
<span>Personal</span>
</div>
</a>
</li>
<li class="" ui-sref-active="active" ui-sref=".test" ng-disabled="formData.$invalid">
<a data-toggle="tab" >
<i class="fa fa-file-text"></i>
<div >
<span class="text-strong">Step 2</span>
<span>Test Date</span>
</div>
</a>
</li>
<li class="" ui-sref-active="active" ui-sref=".testDetail">
<a data-toggle="tab" >
<i class="fa fa-credit-card"></i>
<div>
<span class="text-strong">Step 3</span>
<span>Test Details</span>
</div>
</a>
</li>
</ul>
</div>
<div class="panel-sub-heading">
<div class="inner-all">
<progressbar class="progress-striped active no-margin progress-xs" value='20' max="100" type="success"><i></i></progressbar>
</div>
</div>
<div class="panel-body">
<form class="tab-content form-horizontal" name="formData"novalidate>
<div id="form-views" ui-view></div>
</form>
</div>
</div>
</div>
this is my "personal details" tab
<div class="tab-pane inner-all" id="tab3-1">
<h4 class="page-header">Personal</h4>
<div class="form-group">
<label class="col-sm-2">Name</label>
<div class="col-sm-6" ng-class="{ 'has-error' : formData.name.$invalid && !formData.name.$pristine }">
<input class="form-control" name="name" placeholder="Enter name" ng-model="formData.ngCandName" required>
<p ng-show="formData.name.$invalid && !formData.name.$pristine" class="help-block">Candidate name is required.</p>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error' : formData.background.$invalid && !formData.background.$pristine }">
<label class="col-sm-2">University</label>
<div class="col-sm-6">
<input class="form-control" name="background" placeholder="Background" ng-model="formData.ngCandBackg" required>
<p ng-show="formData.background.$invalid && !formData.background.$pristine" class="help-block">Candidate background is required.</p>
</div>
</div>
<div class="form-group mb-0" >
<label class="col-sm-2">Gender</label>
<div class="col-sm-6" >
<div class="rdio rdio-theme inline mr-10">
<input type="radio" id="male3" ng-model="formData.gender" name="radio" value="male" required >
<label for="male3">Male</label>
</div>
<div class="rdio rdio-theme inline">
<input type="radio" id="female3" name="radio" ng-model="formData.gender" value="female" required>
<label for="female3">Female</label>
</div>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error' : formData.tel.$invalid && !formData.tel.$pristine }">
<label class="col-sm-2" >Telephone number</label>
<div class="col-sm-6">
<input type="number" ng-maxlength="11" class="form-control" name="tel" placeholder="Telephone number" ng-model="formData.ngCandTel" required>
<p ng-show="((formData.tel.$invalid && !formData.tel.$pristine))" class="help-block">Please insert telephone number.</p>
</div>
</div>
<div class="form-group" ng-class="{ 'has-error' : formData.Email.$invalid && !formData.Email.$pristine }">
<label class="col-sm-2">Email</label>
<div class="col-sm-6">
<input type="email" class="form-control" name="Email" placeholder="Email" ng-model="formData.ngCandEmail" required>
<p ng-show="formData.Email.$error.email" class="help-block">Candidate Email is invalid.</p>
</div>
</div>

Resources