# How to change clickability based on state?

**URL:** https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992
**Category:** How-to Discussions
**Created:** [July 26, 2017, 1:08pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992 "2017-07-26T13:08:40Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Iain](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@Iain](https://forums.fusetools.com/u/Iain)
#### Post date: [July 26, 2017, 1:08pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/1 "2017-07-26T13:08:40Z")

</div>

If I have a particular Observable in my state, how would I disable Clicked on a component based on this state?  
In pseudo code:

```auto
<Panel Clickable="{ready}" Clicked="{...}"/>

```

Can I do it on the Panel, or would I separate the two states like this:

```auto
<WhileTrue Value="{ready}">
  <Panel Clicked="{...}"/>
</WhileTrue>
<WhileFalse Value="{ready}">
  <Panel/>
</WhileFalse>

```

Thanks!

---

<div class="post-metadata">

### Author: ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)
#### Post date: [July 26, 2017, 1:11pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/2 "2017-07-26T13:11:17Z")

</div>

How about something like this?

```auto
<Panel>
    <WhileTrue Value="{ready}">
        <Clicked Handler="{...}" />
    </WhileTrue>
</Panel>

```

---

<div class="post-metadata">

### Author: ![Iain](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@Iain](https://forums.fusetools.com/u/Iain)
#### Post date: [July 26, 2017, 1:15pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/3 "2017-07-26T13:15:58Z")

</div>

Awesome. Just out of interest, what happens if I do this?

```auto
<Panel Clicked="{a}">
  <WhileTrue Value="{ready}">
    <Clicked Handler="{b}" />
  </WhileTrue>
</Panel>

```

Does b override a?

---

<div class="post-metadata">

### Author: ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)
#### Post date: [July 26, 2017, 1:17pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/4 "2017-07-26T13:17:20Z")

</div>

No, it doesn’t override it. When `{ready}` is true, both `{a}` and `{b}` will be called on a click.

---

<div class="post-metadata">

### Author: ![Iain](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@Iain](https://forums.fusetools.com/u/Iain)
#### Post date: [July 26, 2017, 1:26pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/5 "2017-07-26T13:26:37Z")

</div>

Ok, so if I have a component like this:

```auto
<Panel ux:Class="my.Button">
  <object ux:Property="Disabled" />
</Panel>

```

…and another component attaches a click handler:

```auto
<my.Button Clicked="{a}" Disabled="{disabled}"/>

```

I want to “somehow” disable the Clicked handler when {disabled} is true.

Is this possible when using Clicked? Or would I need to use a custom property for the click handler?

---

<div class="post-metadata">

### Author: ![Iain](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@Iain](https://forums.fusetools.com/u/Iain)
#### Post date: [July 26, 2017, 1:28pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/6 "2017-07-26T13:28:50Z")

</div>

(Ideally I would want to put this logic inside my.Button, rather than outside it)

---

<div class="post-metadata">

### Author: ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)
#### Post date: [July 26, 2017, 1:31pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/7 "2017-07-26T13:31:28Z")

</div>

Use the property just for the visual style within the component. When using an instance of the button, do it so:

```auto
<my.Button Disabled="{disabled}">
    <WhileFalse Value="{disabled}">
        <Clicked Handler="{a}" />
    </WhileFalse>
</my.Button>

```

The problem is that you need to put the reference to `{a}` callback in the data context where it’s available.

You can, of course, put the `WhileFalse` inside of the component itself, and Fuse will automatically look up the tree and try to figure out where `{a}` lives. Depending on how many instances of `{a}` you have, and on what levels, it may or may not hit the right one.

---

<div class="post-metadata">

### Author: ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)
#### Post date: [July 26, 2017, 1:35pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/8 "2017-07-26T13:35:30Z")

</div>

Oh, and there’s [IsEnabled](https://www.fusetools.com/docs/fuse/visual/isenabled) that you’ll want to take a look at!

---

<div class="post-metadata">

### Author: ![Iain](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@Iain](https://forums.fusetools.com/u/Iain)
#### Post date: [July 26, 2017, 1:40pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/9 "2017-07-26T13:40:24Z")

</div>

Ok, thanks. Decided to go with this in then end I think.

```auto
<Panel ux:Class="my.Button">
  <object ux:Property="Pressed" />
  <object ux:Property="Disabled" />
  <WhileFalse Value="{ReadProperty Disabled}">
    <Clicked Handler="{ReadProperty Pressed}" />
  </WhileFalse>
</Panel>

```

So it’s easier to use the button each time, eg:

```auto
<my.Button Pressed="{a}" Disabled="{disabled}"/>

```

Thanks for your help!

---

<div class="post-metadata">

### Author: ![Iain](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@Iain](https://forums.fusetools.com/u/Iain)
#### Post date: [July 26, 2017, 1:57pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/10 "2017-07-26T13:57:00Z")

</div>

A-ha, so actually it’s as simple as:

```auto
<Panel ux:Class="my.Button"/>

```

```auto
<my.Button Clicked="{a}" IsEnabled="{ready}"/>

```

Is there any way to do simple negation, eg:

```auto
<my.Button Clicked="{a}" IsEnabled="{!disabled}"/>

```

?

---

<div class="post-metadata">

### Author: ![Uldis](https://yyz1.discourse-cdn.com/flex035/user_avatar/forums.fusetools.com/uldis/32/657_2.png) [@Uldis](https://forums.fusetools.com/u/Uldis)
#### Post date: [July 26, 2017, 2:13pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/11 "2017-07-26T14:13:34Z")

</div>

It looks like we are indeed missing some negation UX expressions. ~~We’ll not need… we’ll need to not… we’ll not need to not…~~ We’ll need to fix that.

In the mean time, you will need to do the simple negation in JS.

```auto
var Observable = require("FuseJS/Observable");
var bool = Observable(true);
var invertBool = bool.map(function(x) {
    return !x;
});

```

---

<div class="post-metadata">

### Author: ![Iain](https://avatars.discourse-cdn.com/v4/letter/i/d2c977/32.png) [@Iain](https://forums.fusetools.com/u/Iain)
#### Post date: [July 26, 2017, 2:16pm UTC](https://forums.fusetools.com/t/how-to-change-clickability-based-on-state/2992/12 "2017-07-26T14:16:58Z")

</div>

Ok, not a problem 🙂  
Negation would definitely be useful though!
