Getting the value of a JQueryInstance

168 Views Asked by At

I'm still trying to get to understand how Javascript is wrapped in Seaside, say I have the following query:

(html jQuery: '#myId') hasClass: 'myClass'

How do I get a true or a false out of this? For example in my case I'd love to be able to do:

html anchor
   onClick: 
      (((html jQuery: '#myId') 
          hasClass: 'myClass') 
              ifTrue: [doSomething]
              ifFalse: [doSomethingElse]);
   with: 'Magic Stuff!'

What's the seaside way of doing this?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

Depends where you want to perform the decision on the client or on the server?

Decide and Perform Action on Client

You can use

((html jQuery: '#myId') hasClass: 'myClass') 
   then: aTrueExpression
   else: aFalseExpression

where aTrueExpression' andaFalseExpression' are other (jQuery) JavaScript expressions.

Decide and Perform Action on Server

You serialize the result of your expression into an AJAX callback and perform the action on the Smalltalk side:

html jQuery ajax
   callback: [ :value |
       value = 'true'
           ifTrue: [ " true block " ]
           ifFalse: [ " false block " ] ]
   value: ((html jQuery: '#myId') hasClass: 'myClass')