How can i create dynamicly in ng-model using variable - angularjs

<input ng-model="company.title_{{selectedLang}}"
type="text" placeholder="" class="form-control">
I have already try:
<input ng-model="company.title_[selectedLang]"
type="text" placeholder="" class="form-control">
It doesn't work.
Can anyone help me?

<!-- REPLACE this
<input ng-model="company.title_{{selectedLang}}"
type="text" placeholder="" class="form-control">
-->
<!-- WITH this -->
<input ng-model="company['title_'+selectedLang]"
type="text" placeholder="" class="form-control">

Related

make required option for inputs depending on a checkbox

I have a checkbox as following :
<input type="checkbox" name="bacLibre" id="bacLibre" ng-model="bacLibre">
and other inputs as following :
<div id="bacSection" ng-show="!bacLibre">
<div class="row">
<div class="form-group col-md-6">
<label for="regionalScore">
{{'FME_CANDIDATURE.EDUCATION_INFORMATIONS.REGIONAL_SCORE' | translate}}:
</label>
<input type="number" min="0" max="20" step="0.01" name="regionalScore" id="regionalScore" class="form-control input-lg"
ng-model="candidature.regionalScore"
required>
</div>
<div class="form-group col-md-6">
<label for="bacSecondYearFirstSemScore">
{{'FME_CANDIDATURE.EDUCATION_INFORMATIONS.BAC_SECOND_YEAR_FIRST_SEM_SCORE' | translate}}:
</label>
<input type="number" min="0" max="20" step="0.01" name="bacSecondYearFirstSemScore" id="bacSecondYearFirstSemScore"
class="form-control input-lg"
ng-model="candidature.bacSecondYearFirstSemScore"
required>
</div>
</div>
</div>
as you can see all the inputs are required I want when I check that checkbox to change the state of all the inputs in that <div id="bacSection"> to not required, and then when I uncheck that checkbox to make all the inputs required.
how can I do this ?
Angular has a directive ng-required, use that on the input with a expression that gets changed
<<input type="number" min="0" max="20" step="0.01" name="bacSecondYearFirstSemScore" id="bacSecondYearFirstSemScore"
class="form-control input-lg"
ng-model="candidature.bacSecondYearFirstSemScore"
ng-required='bacLibre'>

salesforce web to lead with "notes"

I'm trying to use Web to Lead functionality of salesforce. I can create a lead, but the Notes field does not get the data I supplied in the form. Here's the form I'm sending:
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST">
<input type=hidden name="oid" value="xxxxxxx">
<input type=hidden name="retURL" value="http://www.mycompany.com">
<label for="first_name">First Name</label><input id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<label for="email">Email</label><input id="email" maxlength="80" name="email" size="20" type="text" /><br>
<label for="company">Company</label><input id="company" maxlength="40" name="company" size="20" type="text" /><br>
Notes:<textarea id="00N6100000C5D5Z" name="00N6100000C5D5Z" type="text" wrap="soft"></textarea><br>
<label for="street">Street</label><textarea name="street"></textarea><br>
<input type="submit" name="submit">
</form>
Every field gets populated in the new lead entry, except Notes. Has anyone ran into this issue? How did you resolve it?
Thanks in advance!
I haven't got why you have specified type="text" with your textarea. Textarea itself is a type.
Can you replace
Notes:<textarea id="00N6100000C5D5Z" name="00N6100000C5D5Z" type="text" wrap="soft"></textarea><br>
With:
Notes:<textarea id="00N6100000C5D5Z" name="00N6100000C5D5Z" wrap="soft"></textarea><br>
Give it a try.

Same value of two inputs angularjs

How can one input be the same value as another input via angularjs? I know how to do this via jquery but not in angularjs. Here is my code:
<body ng-app="peopleApp">
<div ng-controller="myController">
<input class="form-control input-form" ng-model="input.user_code" name="user_code" type="text" maxlength="4" minlength="4" required>
<input class="form-control input-form" ng-model="input.username" name="username" type="text" required>
</div>
</body>
<script type="text/javascript">
var peopleApp = angular.module('peopleApp', []);
peopleApp.controller('myController', function(){
$scope.input = {
'username': $scope.input.user_code
}
});
</script>
So basically what I want is the first input element to be the same value as the second input element
use ng-blur or ng-change
<body ng-app="peopleApp">
<div ng-controller="myController">
<input class="form-control input-form" ng-blur="input.username = input.user_code" ng-model="input.user_code" name="user_code" type="text" maxlength="4" minlength="4" required>
<input class="form-control input-form" ng-model="input.username" name="username" type="text" required>
</div>
</body>
The answer above works, but if you want it to update in real time, just use the same model:
<input class="form-control input-form" ng-model="input.user_code" name="user_code" type="text" maxlength="4" minlength="4" required>
<input class="form-control input-form" ng-model="input.user_code" name="username" type="text" required>
When you change one of the two, the other will update as well. You can also use this as any other tag. For example, this will show what you type on the <p> tag:
<input class="form-control input-form" ng-model="input.user_code" name="user_code" type="text" maxlength="4" minlength="4" required>
<p> {{ input.user_code }} </p>

populate select from input with angularJs

I want to create my custom directive data-from .
data-from="id-employee"
the attribute "data-from" indicates that the inputs of this fieldset must contains the values of the fieldsets which id start with "id-employee"
the user should be able to select a leader from the list of the employee.
Any ideas??
Thanks in advance !!
<form>
<fieldset id="id-employee[0]">
<input type="text" name="name-employee[0]"/>
<input type="text" name="lastname-employee[0]"/>
</fieldset>
<fieldset id="id-employee[1]">
<input type="text" name="name-employee[1]"/>
<input type="text" name="lastname-employee[1]"/>
</fieldset> <fieldset id="id-employee[2]">
<input type="text" name="name-employee[2]"/>
<input type="text" name="lastname-employee[2]"/>
</fieldset>
<fieldset id="id-leader" data-from="id-eployee">
<select id="select-employee">
<option>Select a Team leader</option>
<option id="select-employee-0" value="0">name lastname of the employee 0</option>
<option id="select-employee-0" value="1">name lastname of the employee 1</option>
<option id="select-employee-0" value="2">name lastname of the employee 2</option>
</select>
<input type="text" name="name-leader"/>
<input type="text" name="lastname-leader"/>
</fieldset>
</form>
You can use data binding to achieve this like -
<form ng-init="employees=[]">
<fieldset id="id-employee[0]">
<input type="text" model="employees[0].name" name="name-employee[0]"/>
<input type="text" model="employees[0].lastname" name="lastname-employee[0]"/>
</fieldset>
and then bind it in select
<select ng-model="leader" ng-options="employee.name as employee.name for employee in employees"></select>

How to combine two inputs into one value and bind?

I use 2 Inputs to define an age. Both values should be passed to a new input which is alread binded to rule.data. Is that possible? I'm new with angularjs and probably I have a flaw. Thanks for your tips
HTML
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.from"/>
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.to"/>
<input type="text" class="form-control input-sm" ng-model="rule.data" value="between {{age.from}} and {{age.to}}" />
I do not really understand why you want to use an <input> to format a text with the values of min and max.
You would rather do this, no ?
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.from"/>
<input type="number" class="form-control input-sm" min="1" max="110" ng-mdodel="age.to"/>
<span>between {{age.from}} and {{age.to}}</span>
Does this work for you ?
If the string is just a placeholder for the user age value, you should do this instead :
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.from"/>
<input type="number" class="form-control input-sm" min="1" max="110" ng-mdodel="age.to"/>
<input type="text" class="form-control input-sm" ng-model="rule.data" placeholder="between {{age.from}} and {{age.to}}" />
If you need to get the final string into the model, you can do something like this then:
<input type="number" class="form-control input-sm" min="1" max="110" ng-model="age.from"/>
<input type="number" class="form-control input-sm" min="1" max="110" ng-mdodel="age.to"/>
<input type="text" class="form-control input-sm" ng-model="rule.data" ng-init="rule.data = 'between ' + age.from + ' and ' + age.to" />
(I assume you do not have a controller to initialize the model properly.
If you do, then just add this kind of line inside : $scope.rule.data = 'between ' + $scope.age.from + ' and ' + $scope.age.to;. it should do the trick.)
can vary with many solutions, you can add a custom filter at third combined result ,
<input type="text" class="form-control input-sm" ng-model="rule.data | customFilter:age.from:age.to" value="between {{age.from}} and {{age.to}}" />
app.filter('customFilter',function(){
return function(input ,fromage,toage){
//your code for between
return //your calculated age
}
});

Resources