Reloading a component and passing variables to it

477 views
Skip to first unread message

Jim S

unread,
Jan 17, 2014, 11:32:55 AM1/17/14
to web...@googlegroups.com
Trying to reload a component, passing new parameters to it.


    <script type="text/javascript">
       
function priceListProductSiteEdit( priceListProductId ) {
           
//alert(priceListProductId);
           
//$('#priceListProductEdit2').load('/infocenter/pricing/priceListProduct.load?priceListProductId=' + priceListProductId);
            web2py_component
("{{=URL('pricing', 'priceListProduct.load', vars="{'priceListProductId':" + priceListProductId + "})}}, target='priceListProductEdit');
       
}
   
</script>


But, when my controller function is called, the value passed to the priceListProductId variable is      + priceListProductId +     not the value that is passed to the javascript function.

I'm having a total brain-fart trying to figure out how to pass this properly.

Can someone help please?

-Jim

Richard Vézina

unread,
Jan 17, 2014, 11:43:31 AM1/17/14
to web2py-users
Hello Jim,

what's in priceListProductId ?

I would see this in javascript :

priceListProductId = {{=request.vars.priceListProductId}}

?

Richard


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jim S

unread,
Jan 17, 2014, 12:20:59 PM1/17/14
to web...@googlegroups.com
priceListProductId is an integer that is being passed into the javascript function.  However, I don't know how to specify that on the web2py_component call.  Trying to pass it to the 'vars' parameter but can't get the syntax right.  It isn't in the request object in web2py yet.

-Jim

Jim S

unread,
Jan 17, 2014, 12:26:42 PM1/17/14
to web...@googlegroups.com
For example, when I call the reload using this method, it works:

$('#priceListProductEdit2').load('/infocenter/pricing/priceListProduct.load?priceListProductId=' + priceListProductId);


But am having trouble getting the javascript variable passed to the URL function call.

-Jim

Richard Vézina

unread,
Jan 17, 2014, 1:14:30 PM1/17/14
to web2py-users
I don't think it possible to pass javascript variable to web2py like that, it would be a big security hole if you can...

Not sure how it applies, but when I want to pass vars to component I just call or redirect to URL with the appropriate vars that I want to pass to the component from the master view/controller (the one in which there is component embeded)...

Then, my component just have to pickup the vars with request.vars.var with LOAD()... This can be does also with web2py_component() in javascript as show above...

But maybe you have a different requirement that I don't understand because you don't explained you use case nor showed code...

Richard

Jim S

unread,
Jan 17, 2014, 1:59:56 PM1/17/14
to web...@googlegroups.com
Thanks Richard.  Something you said in there triggered something for me and I think I know what to do now.

Thanks

Will post the solution once I find it.

-Jim

Anthony

unread,
Jan 17, 2014, 2:02:27 PM1/17/14
to web...@googlegroups.com
Remember, everything inside {{...}} is rendered on the server before delivery to the browser, so you can't include JS in there. Instead, should be:

web2py_component("{{=URL('pricing', 'priceListProduct.load')}}" +
                 
"?priceListProductId=" + priceListProductId,
                 target
='priceListProductEdit')

You have to add the query string entirely in JS, so you can't use the web2py URL() function for that part.

Anthony

Jim S

unread,
Jan 17, 2014, 2:42:04 PM1/17/14
to web...@googlegroups.com
Of course that is the answer Anthony!

For some reason I just wasn't able to come up with it today.  Thanks for laying things out clearly, as you always do.

Very much appreciated.

All the best

-Jim
Reply all
Reply to author
Forward
0 new messages