show Error msg when text reach max length angular js \ [closed] - angularjs

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have a text field on which i have used max checked of angular js.
its working absolutely fine but i want to show error in span if text.length reached the max length. like ng-if searchtext.length== max show a message

<form name="myForm">
<input
type="text"
name="myText"
ng-model="myModel"
ng-maxlength="2">
<span ng-show="myForm.myText.$error.maxlength">Error</span>
</form>

using the Angular documentation : maxlength
https://docs.angularjs.org/api/ng/directive/ngMaxlength
Example should be fine for you I hope

Related

AngularJS 1.4 mask input for phone number issues [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm fairly new to dev work and i've run into an issue. supporting an app and they want to do masking on the input for a phone number. They want to have the input be that you can only enter a phone number in a xxx-xxx-xxxx format. Currently we are checking input, but only when we write to the DB.
The app has no masking built into it and is using AngularJS 1.4.9. I was able to locate something at the below URL however I'm having issues with it not working. I can call mask in my html template but it doesn't seem to do anything.
Does anyone have any suggestions or something that is easy to implement? I don't want to re-write a ton of the app. Right now we do the validation on the write to the DB, which can be annoying as you dont get the error till you hit save and then you lost all the data you put into the form.
I'm also very new to Angular, sorry for any misunderstandings i might have.
https://github.com/candreoliveira/ngMask
You can do that without installing any new dependencies using ng-pattern,
running link
<ng-form name="myForm" ng-controller="mainCtrl">
<div>Phone No. :</div>
<div>
<input type="text" placeholder="913-636-7865" name="phone" ng-pattern="phoneNumbr" ng-model="phone" />
<span class="error" ng-show="myForm.phone.$error.required">Required!</span>
<span class="error" ng-show="myForm.phone.$error.minlength">Phone no not less that 10 char.</span>
<span class="error" ng-show="myForm.phone.$error.maxlength">Phone no not more than 11 char.</span>
<br><span class="error" ng-show="myForm.phone.$error.pattern">Please match pattern [913-636-7865]</span>
</div>
Using ng-mask is a good option , but make sure you have it installed and added to your dependency list
angular.module('yourApp', ['ngMask']);
here what should your html look like :
<div class="row">
<div class="col-md-6">
<label>Phone number (Home)</label>
<input type="tel"
name="phone"
mask="999-999-9999"
ng-model="phone"/>
</div>

get ng-model value of span on ng-click in angular js [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to achieve that to get cityName whenever I clicked on city name.
Please tell me what I am doing wrong.
http://plnkr.co/edit/Vb9akn0Qx8ZhTDQxOIoy?p=preview
You can pass the value into your function, like so:
$scope.weatherUpdate = function(cityName) {
And change the HTML file, like so:
<li ng-click="weatherUpdate(x.cityName)" ng-repeat="x in cities">
This way, you can use the cityName variable within your weatherUpdate function
you should pass 'x.cityName' instead of 'cityName' in to the ng-click function.
<li ng-click="weatherUpdate(x.cityName)" ng-repeat="x in cities">
<span ng-model="cityName">{{x.cityName}}</span>
</li>
Here is you code updated.
I have passed cityName to function and assigned it to name variable you want to show.
Also I fixed part of code where you calling weather api to use selected city in query.
Hope it help.
Plnkr Working example

[[object Object]] appear on textbox in angularjs [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
[object Object] is automatically appeared as value in every textbox in my form. May i know what went wrong? It appears after i inserted the attribute name="searchr" in tag. Thanks.
in search.htm:
<form ng-submit="search()" ng-controller="formcontrol" name="searchr">
<input type="search" placeholder="Search here" id="text_search" ng-model="searchr.text" name="text">
in controller.js:
.controller('SearchCtrl', function($scope, $http) { }
<form name="searchr">
This creates an object of type FormController, and stores it into the scope under the name searchr.
<input name="text">
This creates an object of type NgModelController and stores it in the FormController's text attribute.
<input ng-model="searchr.text">
This tells angular that the model of the field (i.e. the text that must be displayed in the field) is searchr.text, but due to the above, searchr.textis the NgModelController object created by angular, which is part of the FormController object created by angular.
Don't use the same name for the form as the name you use to store the model of the form.

Struts2 sending array text input to Action [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a form with some input fields with the same name in order to send an array of values to the action.
<input type="text" name="myInput" value="apple"/>
<input type="text" name="myInput" value="banana"/>
<input type="text" name="myInput" value="grapefruit"/>
Now in the action I have the parameter set with getter and setter. I tried various things:
String myInput
String[] myInput
List<String> myInput
List myInput
Nothing works, the value is always null. I tested using String and sending 1 value only, that works as expected, but the array isn't getting anywhere.
#Aleksandr
I'm sending the form using POST method.
Action is quite simple:
<action name="save" class="com.mypackage.SaveAction">
<result name="success">/saveSuccess.jsp</result>
</action>
Posting this to answer my question.
In the end it seems like the size of the request was too big.

ng-bind-html-unsafe is not working for tabset in angularjs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I'm trying to print html output with tabset attribute but nothing is displaying. Apart from this other html is working fine:
<tabset> <tab heading="Canada"></tab> <tab heading="International"> </tab> <tab heading="U.S."> </tab> </tabset>
<div ng-bind-html-unsafe="properties.value"></div>
Please suggest.
ng-bind-html-unsafe has been removed recently (5 months) from Angular.
See this:
Changes:
remove ng-bind-html-unsafe
ng-bind-html is now in core
ng-bind-html is secure
supports SCE - so you can bind to an arbitrary trusted string
automatic sanitization if $sanitize is available
Use ng-bind-html instead.

Resources