dilip kumar
dilip kumar

Reputation: 517

Is it possible to write conditional check for two variable in one conditional check

I have a case where two condition need to check for disabling button.

sample code , the way i have did

<div class="{{if isallowed 'notallowed'}} {{if isloading 'notallowed'}}">Submit</div>

Thanks.

Upvotes: 0

Views: 99

Answers (3)

dilip kumar
dilip kumar

Reputation: 517

we can achieve this by using helper.

I have created helper for this and working fine for me.

Helper 'isany-true'

import Ember from 'ember';

export function anytrue(params) {
    return params.includes(true)
}

export default Ember.Helper.helper(anytrue);

Example

<div class="{{if (isany-true isdisableprev isloading) 'notallowed'}}">Submit</div>

Upvotes: 0

AlexMA
AlexMA

Reputation: 10192

I like using ember-truth-helpers for the general case:

{{#if (and foo bar)}} foobar! {{/if}}

For tweaking classes (components only), I use classNameBindings.

classNameBindings: [isUrgent]

This adds class is-urgent to component if isUrgent is true in component context.

Upvotes: 1

Ahmet Emre Kilinc
Ahmet Emre Kilinc

Reputation: 6895

You can do it like this:

<div class={{unless isallowed 'notallowed' (if isloading 'notallowed')}}>Submit</div>

Upvotes: 0

Related Questions