In this VXML code either block's expr is true or false interpreter
doesnt read the block and only prints out block3 which doesnt have an
expression so what is the difference for a block to have an expression
value true or false?
<?xml version="1.0" ?>
<!DOCTYPE vxml PUBLIC "-//BeVocal Inc//VoiceXML 2.0//EN"
"http://cafe.bevocal.com/libraries/dtd/vxml2-0-bevocal.dtd">
<vxml version="2.0" xmlns="http://www.w3.org/2001/vxml">
<form id="foo">
<block expr="true">
<prompt>
block1
</prompt>
</block>
<block expr="false">
<prompt>
block2
</prompt>
</block>
<block>
<prompt>
block3
</prompt>
</block>
</form>
</vxml>
According to the VXML 2.0 spec, the expr attribute on a tag has the following function:
"The initial value of the form item variable; default is ECMAScript undefined. If initialized to a value, then the form item will not be visited unless the form item variable is cleared.
Because you have initialized a value for the first two blocks, they are not visited. (The Form Interpretation Algorithm specifies that the first item with an unset value will be visited.) You might be confusing expr with the cond attribute, which can be used to add a condition to an item to additionally control whether the item is visited. See section 2.1.3 of the spec for more details on the expr and cond attributes.
Related
I need to display the next field in my form depending on the last value selected in the form. All fields in my form are independent views, specifically are ng-include.
The idea is not to show all fields when the page loads, and instead, show the next field according to the value selected in the previous field.
Example 1:
My first input (my first ng-include) is a text field, maybe on trigger onBlur check if the value is correct and then show the next field (my second ng-include), then, if that value is correct and then show the next field (my third ng-include).
Example 2:
This time my first input (my first ng-include) is a checkbox field, maybe on trigger onBlur check if the value is correct and then show the next field (my second ng-include), then, if that value is correct and then show the next field (my third ng-include).
Thanks.
Are you familiar with ng-show?
- It shows or hide element depended on value which you declare in ng-show tag.
You can wrap each field (or a group of fields) in ng-form and show the next section depending on the validity of the form of the current section. The fact that elements of the form are delivered via ng-include has little bearing on the approach:
<div ng-form="form1">
<input ng-model="v.one" required min-length="3">
</div>
<div ng-form="form2" ng-show="form1.$valid && !form1.$pending">
<input ng-model="v.two" required min-length="3">
</div>
<div ng-form="form3" ng-show="form2.$valid && !form2.$pending">
<input ng-model="v.three" required>
</div>
This is, of course, at a high-level, and doesn't deal with cases where previous becomes invalid while the next form is showing. For those, more complicated, cases it is better to do the logic in the controller and expose the decision via a function or a scope variable, e.g. showForm2():
<div ng-form="form2" ng-show="showForm2()">
<input ng-model="v.two" required min-length="3">
</div>
I came through the following example of ng-class="expression" in a book.
http://plnkr.co/edit/fJGT5L9HZXvgAiAyXwlW?p=preview
ng-class="{error:isError,warning:isWarning}"
I get the controller logic, but my doubt is in the interpolation happening here.
What does the following scenarios mean (what is the evaluated value) and Why?
ng-class="{error:true,warning:true}"
ng-class="{error:true,warning:false}"
ng-class="{error:false,warning:true}"
ng-class="{error:false,warning:false}"
From the ngClass arguments docs:
The result of the arguments evaluation can be a string
representing space delimited class names, an array, or a map of class
names to boolean values. In the case of a map, the names of the
properties whose values are truthy will be added as css classes to the
element.
So in your case the result of the arguments after evaluation is a map which produces:
ng-class="{error:true,warning:true}"
=> class="error warning"
ng-class="{error:true,warning:false}"
=> class="error"
ng-class="{error:false,warning:true}"
=> class="warning"
ng-class="{error:false,warning:false}"
=> no class attribute
ng-class="{error:true,warning:true}" => class="error warning"
ng-class="{error:true,warning:false}" => class="error"
ng-class="{error:false,warning:true}" => class="warning"
ng-class="{error:false,warning:false}" => no classes set
As you could notice ng-class get just hash where keys are names of classes and values -- conditions (if true than class will be added to class attribute)
So, ng-class just uses angular expression and check what data it returns (string, array or hash-map) then it applies certain parser to get final classes array to put it to class. One of this is described above.
Angular expressions
Angular like as Javascript uses eval mechanism to execute code (expression), but unlike JS Angular uses safe eval called $eval([expression], [locals]) (Docs)
I'm strongly recommending you to read this article about Angular expressions to understand how it works.
Angular will add (or append to the existing class attr) the following class attribute to the element:
class="error warning"
class="error"
class="warning"
No class attribute added
Please note Double {{ }} :
http://docs.angularjs.org/api/ng.directive:ngMouseleave
Please note single Single: { }
http://docs.angularjs.org/api/ng.directive:select
Does it have something to do with "in the quotes" or "in the tag?" Please confirm. And does any one know why?
Of course the vast level of info on the handlebars site does not help:
The double braces are for one-way binding a model to the template, essentially stick the value of the model into that location.
The single braces signify what type of value the attribute expects. For example:
<select
ng-model="{string}"
[name="{string}"]
[required]
[ng-required="{string}"]
[ng-options="{comprehension_expression}"]>
</select>
ng-model expects a string
name (optional) expects a string
required (optional) expects no value
ng-required (optional) expects a string
ng-options (optional) expects an Angular comprehension expression
The string values can be Angular expressions
Versus this, which is just a direct binding:
<body>
<button ng-mouseleave="count = count + 1" ng-init="count=0">
Increment (when mouse leaves)
</button>
count: {{count}}
</body>
Where the value count on the scope replaces {{count}}
Both ways you provide a expression which are like javascript expressions.
HTML attributes that have been extended by angularjs and take an expression can take any expression without using interpolation symbol {{}}. Single {} is just to signify what should be provided.
Everywhere else you use interpolation {{}}
See documentation on expressions here http://docs.angularjs.org/guide/expression
I'm attempting to use ng-show to show/hide labels if content for that label doesn't exist. So for example, if I entered my phone number into the model, then the "Phone:" label would show with the actual number following. It seems though, that ng-show is evaluating the scope/model, not as true/false on the basis of content/no-content...it just seems to evaluate it as false. How do I write it to evaluate on content, not boolean?
<input type="text" ng-model="data.product.user.phone" />
<div ng-show="data.product.user.phone">
<div>Phone:{{data.product.user.phone}}</div>
</div>
I'm really bad at fiddlin' so forgive the shitty fiddle, that doesn't work at all. http://jsfiddle.net/xVZHL/2/
UPDATE: So the fiddle works. But my source code, does not. The only difference is that we are generating and saving the model on backend/elsewhere so it is not being created and controlled on the main page, but it's just not working...I don't know how to show this in a fiddle. Here is my live code that doesn't work.
<field ng-show="data.product.phone" for="phone" model="data.product.phone" placeholder="Phone" type="field-view"> </field>
field is a directive that has the attributes for, model, and placeholder that it injects into the templates/directives within. data.product.phone, for the purposes of this example, definitely has content in it, but does not show up, even though it should, because in the words of angular content = 'truthy'
Like all HTML attributes, you need the = in ng-show:
<div ng-show="data.product.user.phone">
And correcting the fiddle, it works: http://jsfiddle.net/xVZHL/2/
The field tag is not closed correctly
<field ng-show="data.product.phone" for="phone" model="data.product.phone" placeholder="Phone" type="field-view" </field>
Should be:
<field ng-show="data.product.phone" for="phone" model="data.product.phone" placeholder="Phone" type="field-view"> </field>
UPDATE(ANSWERED):: http://github.com/angular/angular.js/issues/2500 http://groups.google.com/forum/#!msg/angular/FqvC0ciG08w/k7KkyJu7zNoJ Through some more googling, I've found that a directive with an isolate scope, it evaluates it as the isolate scope, so since my scope was already data.product.phone, it was looking at data.product.phone in the scope of data.product.phone, which doesn't exist so it was throwing a wrench in the gears. Putting the ngshow in the template the directive calls works fine, plus less code in the directive calls. Thanks guys!
I try to go through a for each loop and increment value of variable to name my label with below code
<set i="0"/>
<div each="var x in Model">
<input name='field-${i}' value='${x.Id}'/>
<set i=i+1 />
</div>
but it did not increment the value of 'i' , how can I increment the value of i in above loop
thanks
The best way to do this is to use the built in indexer that Spark creates in a for loop. The above could be written like this:
<div each="var item in Model">
<input name='field-${itemIndex}' value='${item.Id}'/>
</div>
Even shorter than the original, and no need to track variables yourself. Also, no need to specifically use item, in your case it would be xIndex because x was your instance.
With slight modification:
<var i="0"/>
<div each="var x in Model">
<input name='field-${i}' value='${x.Id}'/>
<set i="i+1" />
</div>
this should work.
The initial 'set' has been changed to 'var' and quotes were added around i+1.