-1

Here's my code in this div tag:

<div className="lk-btn-group btn-group clear">
            {this.state.invoiceId ? <button className="btn btn-primary btn-sm pull-left" onClick={() => this.printInvoice()}>{abp.localization.localize('PrintInvoice')}</button> : null}
            {this.state.delivery.delivery && !this.state.invoiceId ? <button className="btn btn-primary btn-sm pull-left" onClick={() => this.printDeliveryNote()}>{abp.localization.localize('PrintDeliveryNote')}</button> : null}
            {this.state.delivery.delivery == null ? <button className="btn btn-primary btn-sm pull-right" onClick={() => {
             this.markAsDelivered()
            }} disabled={!this.state.beginningPercentage || !this.state.gallonsDelivered}>{this.props.completeDelivery}</button> : <span className="label label-default pull-right"><i className="fa fa-check"></i> {this.props.deliveryComplete}</span>} 
</div>

My question is how do I get an input of 0 (zero) to not be the same as null? I need the ability for the user to go ahead and put a 0 and have my disabled button show rather than be disabled. I believe it's happening at the == null in the fourth line of the div code above, which appears to me to disable the "btn btn-primary btn-sm pull right"

That's fine if the user hasn't entered anything yet, but I also need the 0 to be treated as any other value entered and not just null or empty if that makes sense. I still need all the other functionality to remain the same.

Alexei Levenkov
  • 94,391
  • 12
  • 114
  • 159
zberg007
  • 31
  • 1
  • 6
  • 0 is not the same as null in either C# or JavaScript. Not exactly sure what you mean (obviously you know that `==` and `===` are different... just checking) – Alexei Levenkov Sep 28 '17 at 17:17
  • Possible duplicate of [JavaScript checking for null vs. undefined and difference between == and ===](https://stackoverflow.com/questions/5101948/javascript-checking-for-null-vs-undefined-and-difference-between-and) – Alexei Levenkov Sep 28 '17 at 17:19
  • it's in c# (asp.net mvc project) but the actual file is a .jsx file which compiles to a .js file. All I know is that anytime I put a 0 in there, it still disables the button. I have tried === to no avail. Thanks! – zberg007 Sep 28 '17 at 17:23

1 Answers1

0

I found this, I hope it helps you, essentially you can use typeof to check the type of this.state.delivery.delivery

// typeof this.state.delivery.delivery is a number
if (typeof this.state.delivery.delivery === "number")

This answer expands on this principle. https://stackoverflow.com/a/4514622/6558939

You could also try Number.isInteger(typeof this.state.delivery.delivery) which should return true or false satisfying the ternary operator.

agamemnon
  • 33
  • 3
  • so... syntax wise, would I substitute this: `this.state.delivery.delivery == null` for this: `(typeof this.state.delivery.delivery === "0")` ? – zberg007 Sep 28 '17 at 17:42
  • Yes that should work. `(typeof this.state.delivery.delivery === "number")` should fail whenever `this.state.delivery.delivery` is NaN apparently `Number.isInteger(this.state.delivery.delivery)` should work too. – agamemnon Sep 28 '17 at 17:45
  • I must be doing something wrong syntax wise. I can't get this to work. Just makes my page blank. Thank you, just the same. I haven't found the solution yet. – zberg007 Sep 28 '17 at 19:57
  • Hmm that's a shame, I updated my answer with the other way you should be able to determine if the number is an integer try replacing `this.state.delivery.delivery == null` with `Number.isInteger(typeof this.state.delivery.delivery)` Also I see what you're saying the code you were given is pretty confusing :P that ternary operator is nuts! It's supposed to make things shorter! – agamemnon Sep 28 '17 at 20:07