In this code:
<div class="list">
<label class="item item-input">
<span class="input-label">CEP Origem: </span>
<input type="text" id="origem" ng-model="cep" ui-br-cep-mask>
</label>
<label class="item item-input">
<span class="input-label">CEP Destino: </span>
<input type="text" id="destino" ng-model="cep" ui-br-cep-mask>
</label>
</div>
When I completed any one of the two the other have the same value, how can I change this?
Because both have the same model, provide different model for each input will solve this issue. You can also use object and bind the keys.
<div class="list">
<label class="item item-input">
<span class="input-label">CEP Origem: </span>
<input type="text" id="origem" ng-model="cep.origem" ui-br-cep-mask>
</label>
<label class="item item-input">
<span class="input-label">CEP Destino: </span>
<input type="text" id="destino" ng-model="cep.destino" ui-br-cep-mask>
</label>
</div>
This is simply because both of your inputs are using the same ng-model. Simply set a different one should help you
ng-model defines the variable that will be edited by your input.
So, if your inputs have the same ng-model, it will edit the same variable.
Here you just have to change the ng-model of your second input:
<input type="text" id="origem" ng-model="cep1" ui-br-cep-mask>
<input type="text" id="destino" ng-model="cep2" ui-br-cep-mask>
Related
">
<ion-content>
<h3 class="style3"><strong>Message</strong></h3>
<form name="form1">
<div class="list">
<label class="item item-input" >
<input type="text" placeholder="Enter Number"ng-blur='SendInvit()' ng-model="message.name" name="phone" ng-required="true" />
<span class="error-message" ng-show="form1.phone.$dirty&&form1.phone.$invalid"> </span>
</label>
<input type="text" rows="4" cols="" placeholder="Write Your Message"
class="area" name="phone" ng-model="message.description" ng-maxlength=
"{{maxLength}}" ng-change="updateBody();" ng-required="true">
<span class="error-message" ng-show="form1.phone.$dirty &&form1.phone.$invalid"></span>
<div id="characters">
<span>Characters left: {{maxLength - message.description.length}}</span>
Send
Cancel
Below is the plunker of my work.Please help me with the code
http://plnkr.co/edit/NDGeMcqzpbIqwd8sr5jM
Used ng-disabled when the form is invalid with ng-maxlength. Set the maxlength from your controller.
Max-length:
ng-maxlength="maxlength"
Ng-disabled
ng-disabled="form1.phone.$invalid"
Here is a working example.
https://plnkr.co/edit/FC4vXw1311pnMee8d2Lz?p=preview
if you want simple solution use maxlength="10"!
Good luck.
I have troubles understanding how it works... basically when I submit my form, it is validated without checking the required inputs nor anything else.
I've set the 'novalidate' attribute to disable the HTML5 validation, then I've set all my fields as 'required' (same for my mail input with an email validation), and I'm using 'ngMessages' from Angular to check the inputs (is that even necessary??). But I can still submit the form without any field filled in... What am I doing wrong? Could it come from the fact that I use ng-submit and not ng-click?
Any help is appreciated !
https://jsfiddle.net/WebMoutarde/n1mocvco/
<div ng-controller="MyCtrl">
<form name="form" novalidate ng-submit="vm.signup()">
<div class="list">
<label class="item item-input item-stacked-label noborder">
<span class="input-label">Nom</span>
<input type="text" name="nom" ng-model="vm.nom" required>
</label>
<hr style="border-style: solid;margin-left: 16px;margin-right: 16px;border-color: #e8e8e8;"/>
<label class="item item-input item-stacked-label noborder">
<span class="input-label">Prénom</span>
<input type="text" name="prenom" ng-model="vm.prenom" required>
</label>
<hr style="border-style: solid;margin-left: 16px;margin-right: 16px;border-color: #e8e8e8;"/>
<label class="item item-input item-stacked-label noborder">
<span class="input-label">Mail</span>
<input type="email" name="mail" ng-model="vm.mail" required>
</label>
<hr style="border-style: solid;margin-left: 16px;margin-right: 16px;border-color: #e8e8e8;"/>
<label class="item item-input item-stacked-label noborder">
<span class="input-label">Mot de passe</span>
<input type="password" name="password" ng-model="vm.password" required>
</label>
<hr style="border-style: solid;margin-left: 16px;margin-right: 16px;border-color: #e8e8e8;"/>
<label class="item item-input item-stacked-label noborder">
<span class="input-label">Confirmez votre mot de passe</span>
<input type="password" name="passwordCheck" ng-model="vm.passwordCheck" required>
</label>
<hr style="border-style: solid;margin-left: 16px;margin-right: 16px;border-color: #e8e8e8;"/>
</div>
<div ng-messages="form.$error" role="alert">
<p style="text-align: center;" ng-message="required">You must fill in all fields</p>
<p style="text-align: center;" ng-message="email">Your email address is invalid</p>
</div>
<div class="item noborder">
<button class="button button-block button-positive" type="submit" >Créer un compte</button>
</div>
</form>
</div>
I've seen many SO questions about this but I still missing something...
You could disabled form submit button till form gets into valid state by using ng-disabled directive on form button
<button class="button button-block button-positive"
type="submit"
ng-disabled="form.$invalid">
Créer un compte
</button>
Or even better would be verify form has been valid or ng-submit method and then call your signup method of controller like below.
ng-submit="form.$valid && vm.signup()"
I am using angularjs in my project.
I have below code in my HTML:
<div class="MT10" ng-init="getPaymentDetailsById()">
<div class="panel">
<div class="form-group">
<label> Name:</label>
<span class="rightside">
<input type="text" value="" ng-model="singleGatewayDetails.name" >
</span>
</div>
<div class="form-group">
<label> APP :</label>
<span class="rightside">
<input type="text" value="" ng-model="paymentDetails.id" ng-disabled="appId">
</span>
</div>
<div class="form-group">
<label> APP KEY:</label>
<span class="rightside">
<input type="text" value="" ng-model="singleGatewayDetails.appKey" >
</span>
</div>
<div class="form-group">
<label> APP SECRET:</label>
<span class="rightside">
<input type="text" value="" ng-model="singleGatewayDetails.appSecret">
</span>
</div>
</div>
</div>
now
<span class="rightside">
<input type="text" value="" ng-model="paymentDetails.id" ng-disabled="appId">
</span>
This code displays some data in my textbox. And I want to display that data in textbox in both scenario, that is while editing and while posting new data to server. So it just displays it while editing but not when I want to post new data to server. Basically this textbox will always have some value pre-filled in it. So i am guessing I have to use some condition on that. So please help me how to achieve that.
I think I know what you are getting at. Without seeing your JS file it would be very hard to give you a good example, however using $scope.value in your JS and setting the text to {{value}} in your HTML should provide the desired result.
Now that I understand your question, you could do this:
<input type="text" ng-model="paymentDetails.id" ng-disabled="appId" ng-show="adding"/>
<span ng-hide="adding">{{paymentDetails.id}}</span>
And then in your controller you could control the variable:
$scope.adding = true
and set it to false based on some condition
In my page below everything is working except for the user.productNumber input at the bottom. What I mean is that all the "required" fields are keeping the "Create Account" button disabled but it's like the productNumber input is being ignored. How can I get this working?
<ion-view title="Sign Up">
<ion-content>
<form name="signUpForm">
<div class="list">
<label class="item item-input item-stacked-label">
<input data-ng-model="user.email" data-ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*#[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/" type="email" placeholder="user#mail.net" required>
</label>
<label class="item item-input item-stacked-label">
<input data-ng-model="user.password" type="password" placeholder="password" required>
</label>
<label class="item item-input item-stacked-label">
<input data-ng-model="user.passwordAgain" type="password" placeholder="password (again)" required>
</label>
<li class="item item-checkbox">
<label class="checkbox">
<input data-ng-model="user.newsletter" type="checkbox" checked>
</label>
Weekly Newsletter
</li>
<label class="item item-input item-stacked-label">
<input data-ng-modal="user.productNumber" data-ng-pattern="/^[a-zA-Z0-9-]{8}$/" type="text" placeholder="Product Number" required>
</label>
<button data-ng-click="createAccountClick()" data-ng-disabled="signUpForm.$invalid" class="button button-full button-positive">
Create Account
</button>
</div>
</form>
</ion-content>
</ion-view>
This is because you mispelled data-ng-model with data-ng-modal.
Simply change:
data-ng-modal="user.productNumber"
with
data-ng-model="user.productNumber"
I have the following HTML, I need to require a radio selection. Not sure how to do it in AngularJS.
<div class="form-group">
<label class="control-label pull-left"><small>Type of M (<i>check one</i>):</small></label>
<div class="col-md-5 pull-left">
<label class="radio-inline pull-left">
<input type="radio" name="radio" ng-model="m.pr.MType" value="PrRep"> PrRep
</label>
<label class="radio-inline pull-left">
<input type="radio" name="radio" ng-model="m.pr.MType" value="LProd"> LProd
</label>
</div>
<div class="input-group col-md-3">
<div class="input-group-sm">
<label><small>Prod LNum</small></label>
<input type="text" class="form-control" id="provProdLNum" ng-model="m.pr.prodLNum" ng-required="m.pr.MType != 'PrRep'" />
</div>
</div>
</div>
I've tried this:
<input type="radio" name="radio" ng-model="m.pr.MType" value="PrRep" required> PrRep
<input type="radio" name="radio" ng-model="m.pr.MType" value="LProd" required> LProd
and this:
<input type="radio" name="radio" ng-model="m.pr.MType" value="PrRep" ng-required="m.pr.MType != ''"> PrRep
<input type="radio" name="radio" ng-model="m.pr.MType" value="LProd" ng-required="m.pr.MType != ''"> LProd
Not sure which is the correct one to use here...
Use ng-required. In your first example, the permanent presence of the required attribute on all the radio buttons within a group will result in the form not validating.
Validate Radio Button AngularJS