I am trying to pass an input name to ng-show.
When the input's name is not an array, this works just fine (if it's just 'entity' instead of 'entity[entity_name]'), but when there's an array it's not working.
something about this syntax - 'ng-show = "investForm.entity[entity_name].$error.pattern"' is wrong:
<form name="investForm">
<label>Entity Name</label>
<input name="entity[entity_name]" rc-forms ng-pattern="/^[A-Za-z]+$/" type="text" ng-model="invest.entity_name" ng-required="invest.is_entity" />
<div ng-show="investForm.entity[entity_name].$dirty && investForm.entity[entity_name].$invalid">
<span ng-show="investForm.entity[entity_name].$error.pattern">Error: Please use English characters only!</span>
</div>
</form>
I found this question pretty intriguing, so I've been Googling for a while.
Apperently your problem is a JavaScript syntax error and I found it here:
angularjs form can not refer to input control when input name is array
You can use square-brackets. You have to reference your form element like this:
investForm['entity[entity_name]'].$error.pattern
I don't think you can use square brackets for the form name. Try replacing it with an underscore or something:
<form name="investForm">
<label>Entity Name</label>
<input name="entity_entity_name" rc-forms ng-pattern="/^[A-Za-z]+$/" type="text" ng-model="invest.entity_name" ng-required="invest.is_entity" />
<div ng-show="investForm.entity_entity_name.$dirty && investForm.entity_entity_name.$invalid">
<span ng-show="investForm.entity_entity_name.$error.pattern">Error: Please use English characters only!</span>
</div>
</form>
Related
I want to display an integer number in html which I get from a rest api call as json response. But in my HTML page it is displayed with a comma. So now when I want to accept the fields and save my record, the field shows a error message: "Please enter a valid schema".
That's my code:
HTML:
<div class="mb-3">
<label for="disabledTextInput" class="form-label">Pages</label>
<input type="number" class="form-control" name="pages" value="${book.pages}">
</div>
The field in json:
"pageCount": 1531
That's the result with separator:
Hoply can help. You can add this code, just adjust it with your code
<?php
//hide comma with replace function
$book_pages= str_replace(",", "", $book.pages);
?>
Sorry my bad, I forgot to tell that is written in FreeMaker.
So the solution is just writing it with some FreeMarker logic:
<input type="number" class="form-control" name="pages" value="${book.pages?c}">
html code:
<div id="1" class="grid-item"> <input type="text" size=1px value=""></div>
After entering the value in input section,i want to access the contents what i have enetered.
can anyone please help me in this question.
i didn't quite understand what you meant but i assume you meant the following ?
let input = document.getElementById('input')
let h1 = document.getElementsByTagName('h1')[0]
input.addEventListener('input', () => {
h1.textContent = input.value
})
<div id="1" class="grid-item"> <input type="text" size=1px value="" id='input'> <h1></h1></div>
Requires JavaScript or BackEnd But if you don't mind I will explain the javascript
...............
First, choose a unique identifier for your input, for example "MyInput":\
<div>
<input type="text" id="MyInput" value="">
</div>
It doesn't matter where it is ( form , input and ... )
Now let's go to JavaScript:( I attach it to a sticker )\
<a onclick=" alert( document.getElementById('MyInput').value ) "> Show Value Input</a>
You may not understand what this command is
I'm just referring to the onclick input
With the "alert" command the browser will show you something and if you know js, you know this
The document.getElementById command takes an ID and finds that tag, which you can access by typing a dot followed by the entry name.
For example, when you write something in your input, the input is a value and the fog is filled with that value.
From now on, every time you click on the a tag, you will be shown the input value
Complete code:
<div>
<input type="text" id="MyInput" value="">
</div>
<a onclick=" alert( document.getElementById('MyInput').value ) "> Show Value Input</a>
If you have any questions, send me an email:
amp.it.ir.go#gmail.com
;-)
I'm using ng-pattern :
<input type="text" ng-model="price" name="price_field" ng-pattern-restrict="/^[4]*$/" required only-digits>
Please let me know what to do that it does not accept any other numbers except 4. I am using directive for digits that is only-digits.
EDIT: SORRY WRONG ANGULAR VERSION - but if you can transform this to angularjs it will be work!
You can use (input) event in you HTML input element
<input type="number" (input)="check($event)">
Than in your ts you cehck value of input
check(event) {
console.log(event);
if (+event.data !== 4) {
event.target.value = '';
}
}
The pattern which you are mentioned is not a valid regex pattern. Instead of that try to use this /^([4]){1}?$/ Hope you will get it.
<input type="text" ng-model="price" name="price_field" ng-pattern-restrict="/^([4]){1}?$/" required only-digits>
Try to use below restrict pattern :
<input type="text" ng-model="price" name="price_field" ng-pattern-restrict="^[4]{1}?$" required only-digits>
And below validation message :
<div ng-messages="myForm.price_field.$error">
<span ng-message="pattern">Not a valid number!</span>
</div>
How can I concatenate string in HTML Attribute. I am using angular controller and in the part where I write some array in HTML (Code is below), I want to give input tag name that is "kolicina" + {{idhrana}} witch is attribute of object jelo.
<div class = "rezultat" ng-repeat="jelo in hrana | filter:pretrazi_namirnice">
<div> {{jelo.naziv}} </div>
<div> {{jelo.energijaKCal}}</div>
<div> {{jelo.proteini}}</div>
<div> {{jelo.uglj_hidrati}}</div>
<div> {{jelo.masti}}</div>
<div><input type=text nama="kolicina"+{{idhrana}}></div>
<div><input type="button" ng-click = 'dodaj(jelo)' value="Dodaj"></div>
</div>
You can do it like so:
<input type=text name="kolicina{{idhrana}}"></div>
No need to explicitely concatenate it.
Also, I think you had a typo with nama versus the name-attribute.
http://plnkr.co/edit/uJcDZkrGNqzSibpgkTc9?p=preview
<input type=text name="kolicina {{idhrana}}">
working plnkr for understanding. hope this will help you.
Different 'ng-model name' in ng repeat - Possible?
<div ng-repeat="todo in todos">
<input type="text" ng-model="tag">
<button type="submit"ng-click="addTodo(todo._id)">Add</button>
</div>
In this case, there are some repeat todo item (based on todos json data) will show on frontend
My Problem: What i type on any input field , all input field showing same data
I need different ng-model name on each input field , I guess like this ng-model="tag($index)"
You could place the newly created model inside tag array by its $index, while declaring model inside the tag you should use array notation [] instead of ()
ng-model="tag($index)"
should be
ng-model="tag[$index]"
Markup
<div ng-repeat="todo in todos">
<input type="text" ng-model="tag[$index]">
<button type="submit"ng-click="addTodo(todo._id)">Add</button>
</div>
It is possible like below
<div ng-repeat="todo in todos">
<input type="text" ng-model="tag[todo]"> <--todo.key-->
<button type="submit"ng-click="addTodo(todo._id)">Add</button>
</div>
You can do it like this:
<input type="text" ng-model="todo.tag">