Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to check if a value is defined? #606

Closed
georgeu2000 opened this issue Sep 30, 2014 · 2 comments
Closed

How to check if a value is defined? #606

georgeu2000 opened this issue Sep 30, 2014 · 2 comments

Comments

@georgeu2000
Copy link

The following code is raising an error:

input = element.children( "input[ name='name' ]" )
if input.attr( 'type' ) == 'radio'
  ...

This works fine, except sometimes type is undefined:

'undefined' is not an object (evaluating 'input.$attr("type")['$==']')

What is a good way to protect the if statement from undefined values? I guess the JS way is typeof( input.attr( 'type' )) == 'undefined', but not sure how to generate this from Ruby.

I tried defined() and .nil? but they don't seem to do this check. Perhaps there is one way (or there should be) one way of doing this?

@meh
Copy link
Member

meh commented Sep 30, 2014

That's a problem caused by the library you're using (I assume opal-jquery).

@georgeu2000
Copy link
Author

OK, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants