javascript-kit icon indicating copy to clipboard operation
javascript-kit copied to clipboard

Error thrown for `getBoolean` when fragment does not yet exist.

Open ctrlplusb opened this issue 8 years ago • 5 comments

  getBoolean: function(name) {
    var fragment = this.get(name);
    return fragment.value && (fragment.value.toLowerCase() == 'yes' || fragment.value.toLowerCase() == 'on' || fragment.value.toLowerCase() == 'true');
  },

Need to check if fragment is not null?

I had a "Select" type with yes/no, and I show default text of "no". User's then don't select "yes" assuming the value is "no" and then when I try to interpret the value I get the following error:

TypeError: Cannot read property 'value' of null

ctrlplusb avatar Jul 13 '16 14:07 ctrlplusb

yes, we need to do a better job with the NPE in general (not just for getBoolean). We're working on a newer version that will improve that.

erwan avatar Sep 29 '16 08:09 erwan

Hi @erwan, any update on this? I vote it returns false if not yes, on, true — so including undefined and null. Thanks

evvvritt avatar Apr 04 '17 18:04 evvvritt

@arnaudlewis I believe you worked on that?

erwan avatar Apr 04 '17 19:04 erwan

@erwan no i did not but thanks for your message. I'll take a look asap @evvvritt

arnaudlewis avatar Apr 04 '17 19:04 arnaudlewis

Also if you call api.getLink('text-url').url(). It errors out if it doesn't exist, this shouldn't be the case in my opinion. You could use lodash get method to solve it: https://lodash.com/docs/4.17.4#get. @erwan

sarunast avatar Apr 29 '17 15:04 sarunast