Re: Re: [Seaside] How do I use JQuery with Javascript variable

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Re: [Seaside] How do I use JQuery with Javascript variable

chicoary
Thanks Johan for your response.

I saw my omission of the code snippet "addLoadscript html document:"
before your reply. I put also indicated halts but they were not
reached during the execution.

Another question I have is this: the original code runs entirely in
Javascript on the client. There is no way to do the same in Seaside
with JQuery?

>
> Francisco,
>
> Wait... now I see that you are just generating the script but you are not attaching it anywhere. The script is therefore never rendered to the client side.
> You original code snippet contained:
>
> html document addLoadscript: <script>
>
> which is correct, but you can also attach the script to the testButton like this:
>
> html button
>        script: <script> ;
>        id: ...
>
> >From there on, I think it should work but I'm also just writing this off the top of my head.
>
> With <script> being:
>
>        (html jQuery: #testButton)
>                onClick: (html jQuery ajax
>                                callback: [:val | checkedValue := val]
>                                value: (JSStream on: '$(''[name="someRadioGroup"]:radio:checked").val()');
>
>                                onComplete: ((html jQuery: #result) load
>                                                html: [:renderer | renderer html: 'The radio element with value
> <tt>' , checkedValue , '</tt> is checked.'])).
>
> best
> Johan
>
> On 30 Jan 2012, at 02:09, Francisco Martins wrote:
>
>> Thanks Johan for your answer.
>>
>> See my code below:
>>
>> renderContentOn: html
>>       | checkedValue |
>>       (html jQuery: #testButton)
>>               onClick: (html jQuery ajax
>>                               callback: [:val | checkedValue := val]
>>                               value: (JSStream on: '$(''[name="someRadioGroup"]:radio:checked").val()');
>>
>>                               onComplete: ((html jQuery: #result) load
>>                                               html: [:renderer | renderer html: 'The radio element with value
>> <tt>' , checkedValue , '</tt> is checked.'])).
>>       html
>>               form: [html
>>                               div: [html label for: #radioYes;
>>                                                with: 'What is your answer?'.
>>                                       html
>>                                               radioGroup: [:group |
>>                                                       html radioButton id: #radioYes;
>>                                                                group: group;
>>                                                                name: #someRadioGroup;
>>                                                                value: #yes;
>>                                                                selected: true;
>>                                                                with: 'Yes'.
>>                                                       html radioButton id: #radioNo;
>>                                                                group: group;
>>                                                                name: #someRadioGroup;
>>                                                                value: #no;
>>                                                                with: 'No'.
>>                                                       html radioButton id: #radioMaybe;
>>                                                                group: group;
>>                                                                name: #someRadioGroup;
>>                                                                value: #maybe;
>>                                                                with: 'Maybe'.
>>                                                       html radioButton id: #radioConfused;
>>                                                                group: group;
>>                                                                name: #someRadioGroup;
>>                                                                value: #confused;
>>                                                                with: 'I dunno']].
>>                       html
>>                               div: [html button type: #button;
>>                                                id: #testButton;
>>                                                class: #green90x24;
>>                                                with: 'Which?'].
>>                       html div id: #result]
>>
>> Unfortunately the code did not work. I did something wrong?
>>
>>> Francisco,
>>>
>>> If you want to include a callback to the server on click, this is how I would do it:
>>>
>>> (html jQuery: #testButton) onClick: (
>>>        (html jQuery ajax
>>>                callback: [:val |  checkedValue := val]
>>>                value: (JSStream on: '$(''[name=''someRadioGroup'']:radio:checked'').val()');
>>>                onComplete: (html jQuery: #result) load html: [:renderer| renderer html: 'The radio element with value <tt>' , checkedValue, '</tt> is checked.'])
>>>
>>> This effectively makes two callbacks: one to retrieve the value and one to render the html.
>>>
>>> Johan
>>
>> --
>> Sds.,
>>
--
Sds.,

Francisco Ary Martins
http://chicoary.wordpress.com
----
"A filosofia não é senão uma poesia sofisticada."
Montaigne

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: How do I use JQuery with Javascript variable

Johan Brichau-2

On 30 Jan 2012, at 19:19, Francisco Martins wrote:

> I saw my omission of the code snippet "addLoadscript html document:"
> before your reply. I put also indicated halts but they were not
> reached during the execution.

Hm... I don't catch a reason why this would not work.
Are you not getting any javascript errors in the browser console?

> Another question I have is this: the original code runs entirely in
> Javascript on the client. There is no way to do the same in Seaside
> with JQuery?

Of course you can. I just assumed you were implying a request to retrieve the value also server-side.

If you do not need the value server-side, I would not write that piece of JS using Seaside's jQuery-Javascript wrappers. You can either include the script in a function defined in an external file or write it directly in a string:

html button
        onClick: <entire js script in a Smalltalk string -- or function call to the script included in an external file>

cheers
Johan_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Re: [Seaside] How do I use JQuery with Javascript variable

chicoary
In reply to this post by chicoary
Johan, thanks for your answers. See below my considerations:

>
> On 30 Jan 2012, at 19:19, Francisco Martins wrote:
>
>> I saw my omission of the code snippet "addLoadscript html document:"
>> before your reply. I put also indicated halts but they were not
>> reached during the execution.
>
> Hm... I don't catch a reason why this would not work.
> Are you not getting any javascript errors in the browser console?

Yes, but I could not find the cause.

The console of Safari shows the following errors:

jqueryinactionhack:1SyntaxError: Parse error
jqueryinactionhack:1ReferenceError: Can't find variable: onLoad

>
>> Another question I have is this: the original code runs entirely in
>> Javascript on the client. There is no way to do the same in Seaside
>> with JQuery?
>
> Of course you can. I just assumed you were implying a request to retrieve the value also server-side.

No. I wanted to replicate the functionality found in examples from the
book JQuery in Action. It seems to me that the unobtrusive style is
not feasible in Seaside with JQuery.

>
> If you do not need the value server-side, I would not write that piece of JS using Seaside's jQuery-Javascript wrappers. You can either include the script in a function defined in an external file or write it directly in a string:
>
> html button
>        onClick: <entire js script in a Smalltalk string -- or function call to the script included in an external file>

I tried this with the code below:

html
                                div: [html button type: #button;
                                                 id: #testButton;
                                                 class: #green90x24;
                                                 onClick: self javascriptStream;
                                                 with: 'Which?'].
                                               
JQIARadioGroupExample>>javascriptStream
        ^ JSStream new nextPutAll: 'var checkedValue = $(';
                 nextPut: $';
                 nextPutAll: '[name=';
                 nextPut: $";
                 nextPutAll: 'someRadioGroup';
                 nextPut: $";
                 nextPutAll: ']:radio:checked';
                 nextPut: $';
                 nextPutAll: ').val();';
                 nextPutAll: '$(';
                 nextPut: $';
                 nextPutAll: '#result';
                 nextPut: $';
                 nextPutAll: ').html(';
                 nextPut: $';
                 nextPutAll: 'The radio element with value <tt>';
                 nextPut: $';
                 nextPutAll: ' + checkedValue +';
                 nextPut: $';
                 nextPutAll: '</tt> is checked.';
                 nextPut: $';
                 nextPutAll: ');'
               
Almost works. However does not show the value of the radio button
selected. Always shows the same string "on".
--
Sds.,

Francisco Ary Martins
http://chicoary.wordpress.com
----
"A filosofia não é senão uma poesia sofisticada."
Montaigne
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside