I'm having trouble with a dust if condition. I have a partial that points to 2 different dust templates depending on the Country code
{>"receipt/merchantInfo/merchantInfo_{countryCode}"/}
I'm trying to make an if else condition that will figure out if the {countryCode} is US.
Example:
{#if cond="'{countryCode}' == 'US'"}
<p>is country code US</p>
{:else}
<p>is NOT country code US</p>
{/if}
This isn't working. Anyone have an idea where I went wrong with this?
The #if helper has been deprecated because of a potential security hole (it uses eval on the condition). I would recommend using the #eq helper instead.
{#eq key=countryCode value="US"}
<p>is country code US</p>
{:else}
<p>is NOT country code US</p>
{/eq}
If that doesn't work, make sure countryCode is available in your context (you can use {#contextDump/} for that).
I would do this:
{#select key=countryCode }
{#eq value="US"}<p>is country code US</p>{/eq}
{#eq value="UK"}<p>is country code UK</p>{/eq}
{#default}<p>is NOT country code US or UK</p>{/default}
{/select}
Make sure you are using version 1.x or later.
Make sure you have the Helpers loaded. I ran into this the other day. You need it for this to work and it won't error telling you that it isn't.
If you are enamored of #if but don't like the security issues around its use of eval, you can use my alternative #if helper. It provides an attribute test="expr" to specify your if condition. eval is NOT used to evaluate the expression.
Variables in the expression are restricted to dust names and path used to access values from the context. Constants are JavaScript integer, float, hex and string forms ("xx" or 'xx'). Operands can be a "variable", a constant, or a binary or unary expression yielding a value. Relational operators are <, >, <=, >=, ==, !=. Boolean operators are ! (unary), || and &&.. Operator precedence is the same as JavaScript and parentheses are allowed for clarity or for when the precedence is not what you want.
Here is an example:
{#if test="state == 'CA' || state == 'NY'"}
true stuff goes here
{:else}
false stuff goes here
{/if}
Note that it still has code to allow the cond="expr" attribute that uses eval(). This provides a migration path for existing code.
You can install it as an npm module (https://npmjs.org/package/dustmotes-if).
You can also use:
{#key}
Some content
{:else}
Some other content, if key doesn't have a value
{/key}
For example:
Data
{
firstName: "Mickey",
lastName: "Mouse",
website: null,
phone: "1-800-DISNEYWORLD"
}
Dust Template
<p>First Name: {firstName}</p>
<p>Last Name: {lastName}</p>
{#website}
<p>Website: {website}</p>
{:else}
<p>Phone: {phone}</p>
{/website}
Output:
First Name: Mickey
Last Name: Mouse
Phone: 1-800-DISNEYWORLD
Related
I am currently working on an email template, and I can't seem to be able to reference a field in a IF statement.
The current line I'm having trouble with:
{!IF(Demande_CPT__c.Reponse_Partenaire__c ="Place disponible",”{!Demande_CPT__c.Date_expiration_option__c}”,"notfrench")}
We tried :
{!IF("{!Demande_CPT__c.Reponse_Partenaire__c}" !="Place disponible",”{!Demande_CPT__c.Date_expiration_option__c}”,"notfrench")}
{!IF("{!Demande_CPT__c.Reponse_Partenaire__c}" !="Place disponible",Demande_CPT__c.Date_expiration_option__c,"notfrench")}
but nothing seems to work...
The field evaluates to true and we can get a string to show up but not the field reference. I hope I make sense.
If you have any idea !
Thank you
You already are in the "merge field syntax" of {!text has special meaning here}, you don't need another {! inside it. And your quote signs are wrong, they need to be plain "", not fancy „“. If you edited the template in MS Word it likely injected some rubbish in it with hidden <span></span> tags that also can completely mess the field merging up.
Try with {!IF(Demande_CPT__c.Reponse_Partenaire__c = "Place disponible",Demande_CPT__c.Date_expiration_option__c,"notfrench")}
What is it, normal template or Visualforce? From what I remember normal templates are limited and for IFs you might have to waste a formula field... But Visualforce should work OK
Some more help: https://trailblazers.salesforce.com/answers?id=90630000000gpkYAAQ
i am using KeyFilter Module of primeng here is my code :
<input type="text" pInputText [(ngModel)]="price.TintCost" [pKeyFilter]="patternDecimal" name="tintCost" required="true" />
here is my typescrip code :
patternDecimal: RegExp = /^[0-9]+(\.[0-9]{1,2})?$/;
and here is version of primeng :|
"primeng": "^5.2.0-rc.1",
i tested in regex then i can type dot(.) but when i apply to KeyFilter, it doesn't allow the dot(.). Someone help me, please
I solved this problem by adding a mask as default
KeyFilter.DEFAULT_MASKS['currencyRegex'] = /^-?(?:0|[1-9]\d{0,2}(?:,?\d{3})*)(?:\.\d+)?$/;
I solved this problem by change the pValidateOnly property to true.
The problem is that the KeyFilter check any press on keyboard and if the complete value is no the correct, then dont permit write, just if you copy and paste the value.
In the documentation say
Instead of blocking a single keypress, the alternative validation mode
which is enabled with pValidateOnly property validates the whole input
with a built-in Angular validator.
https://www.primefaces.org/primeng-6.1.6/#/keyfilter
Example that work for me.
Component.ts
public twoDecimal: RegExp = /^\s*-?(\d+(\.\d{1,2})?|\.\d{1,2})\s*$/
Component.html
<input name="decimalField"
#decimalField="ngModel"
[pKeyFilter]="twoDecimal"
[pValidateOnly]="true"
[(ngModel)]="item.decimalField"
type="text" pInputText>
<div *ngIf="!decimalField.valid" class="alert alert-danger">
<p>Incorrect format.</p>
</div>
The answer of #Norberto Quesada is correct.
Without pValidateOnly the regex will validate on every key stroke.
Let's say you want to enter the value "47.11":
You begin to enter "4" => this would be valid, no input blocked.
Same for "47"
As soon as you enter "47. => validation fails, input blocked.
I was thinking maybe it's possible to enter "4711" first and then the "." in between but for some reason this doesn't seem to work, too... Maybe this is a bug?
Anyways, you can take a look at this stackblitz example for better understanding.
I've also prepared an example of using ValidateOnly and in addition to that restrict the input to only numbers using keyDown event
I wrote a Ember/Handlebars helper to format a date using Moment.js:
Ember.Handlebars.registerBoundHelper('formattedDate', function(date, format) {
var formattedDate = moment(date).format(format);
return new Handlebars.SafeString(formattedDate);
});
Now, I want to use that in tandem with an Ember input helper like so (where startDate is a property on the model in scope):
{{input id="startDatePicker" class="form-control" value={{formattedDate startDate 'MMM D'}} required=true}}
But that doesn't work and throws a syntax error. Is there any way to do this?
You can avoid a syntax error by using a subexpression (see more about subexpressions here).
So, you would do:
{{input id="startDatePicker" class="form-control" value=(formattedDate startDate 'MMM D')}}
at which point you won't get a syntax error, but it still will behave weird. What I suggest you do instead is implement a computed property for formatted date instead. See the following answer I recently gave, which should give you a good starting point
https://stackoverflow.com/a/28774170/908842
This is my inspect element snippet:
<div>
<map>
<area href="javascript:void(0)" log="miw" ... shape="poly" title="lender_marker test#example.com">
<area href="javascript:void(0)" log="miw" ... shape="poly" title="lender_marker othertest#example.com">
</map>
</div>
The ... represents a bunch of other tags that I won't include. FYI these elements are from Google Maps API V3 in JS, and I'm using this great tutorial to try to test, except the tutorial works in Selenium and I'd like to use Capybara/ Rspec. Also, used this post to formulate the selectors in the first place.
I need to do two things in my integration tests:
Count # of lender_marker regardless of email
Click on lender_marker with a specific email
For #1...
While I'd love to count just the lender_markers regardless of email, I figure if I can't even find the lender_marker test#example.com I won't worry about finding just lender_marker, hence the tests as they're written below
Also the variations layer, so I've tried every possible permutation of the below
Trials:
#Base test
page.should have_selector("area[title='lender_marker test#example.com']")
#First variation: change selector statement
page.assert_selector("area[title='lender_marker test#example.com']")
#Second variation: no quotes
page.should have_selector(area[title='lender_marker test#example.com'])
#Third variation: use map
page.should have_selector("map[title='lender_marker test#example.com']")
#Fourth variation: use div
page.should have_selector("div[title='lender_marker test#example.com']")
For #2, I can't even try it until I've first off been able to locate the area object, but I can't...
There is nothing wrong with your CSS-selector, which leads me to believe it is a visibility issue. The tutorial you reference is using find_elements, which in Selenium will find all elements matching the selector. In contrast, when Capybara looks for elements it only returns elements that match the selector and are determined to be visible to the user.
In other words, I am guessing that the area elements exist but Capybara does not think they are visible. You likely need to trigger something to make the areas become visible.
However, you can validate that the elements exist, regardless of visibility, by using the :visible option:
# Validate that a specific area exists in the DOM
page.should have_selector('area[title="lender_marker test#example.com"]', visible: false)
# Count the number of lender_markers
page.all('area[title^="lender_marker"]', visible: false).length
#=> 2
# Count the number of lender_markers with minimum in case of async loading
puts page.all('area[title^="lender_marker"]', visible: false, minimum: 2).length
#=> 2
# Validate the number of lender_markers
page.should have_selector('area[title^="lender_marker"]', visible: false, count: 2)
I need to display some block depending on the current views variable in comparison to some string:
PSEUDO code is:
{{#if view.someVariable "desiredValue"}}
Hurray desiredValue exists in this view!
{{else}}
Sorry, doesn't match...
{{/if}}
Of course it doesn't work as if statement allows only one param. I tried with custom registerHelper of Handlebars, but it doesn't resolve the view.someVariable, instead uses it as a string (although view.someVariable is defined and has value).
Finally I also tried with Handlebar's registerBoundHelper - it resolves the params BUT doesn't support Handlebar's blocks, what's more tries to resolve the string as an object, so fail again. Pure madness!
My views are very dynamical they depends on many factors also from backend and approach from the pseudo code would be perfect for resolving it. Is there any way to do that?
Edit:
There is a sample of what I want ... http://jsfiddle.net/biesior/dMS2d/ looks quite trivial...
[if] statement inside the each is pseudo code of course
You can just declare a computed property, something like isDesired on your view, which would compare someVariable to your string:
App.MyView = Ember.View.extend({
// ...stuff...
isDesired: Ember.computed.equal('someVariable', 'desiredValue')
});
And have a simple conditional in the template:
{{#if view.isDesired}}
Hurray desiredValue exists in this view!
{{else}}
Sorry, doesn't match...
{{/if}}