Load component in a <span>?

68 views
Skip to first unread message

webm...@trytha.com

unread,
Mar 24, 2016, 12:51:33 PM3/24/16
to web2py-users
I want my component to load in a span() instead of the default div(class="data-w2p_remote").  Anyone know the best way to do this?

Anthony

unread,
Mar 24, 2016, 1:26:50 PM3/24/16
to web2py-users
If you're talking about using the LOAD helper, it only generates a DIV, and the JS code only looks for DIVs. Would setting it's display to inline do the trick:

mycomponent = LOAD(..., _style='display:inline')

If not, you should be able to do something like this in the view (not tested):

<span id='mycomponent'></span>
<script>$.web2py.component('{{=URL(...)}}', 'mycomponent', el=$('#mycomponent'));</script>

Anthony

webm...@trytha.com

unread,
Mar 24, 2016, 1:38:04 PM3/24/16
to web2py-users
Works for my use case, thanks!  Got so wrapped up in not wanting to do anything global in my CSS, I completely drew a blank on defining an in-line style.  Thanks!

Anthony

unread,
Mar 24, 2016, 4:11:39 PM3/24/16
to web2py-users
You could also do:

LOAD(..., _class='w2p_component')

and then add a CSS rule for that class.

Anthony

Michael Beller

unread,
Mar 26, 2016, 7:51:07 AM3/26/16
to web2py-users
You may be able to use jquery unwrap, wrap, or replace

For example, I want to load a component and not generate the wrapping DIV so I added a unique id to the top element in my view.load file and this inline at the bottom:
<script>
  $("#unique-id").unwrap();
</script>

I think you may be able to use replace also.

On Thursday, March 24, 2016 at 12:51:33 PM UTC-4, webm...@trytha.com wrote:

Anthony

unread,
Mar 26, 2016, 10:10:09 AM3/26/16
to web2py-users
On Saturday, March 26, 2016 at 7:51:07 AM UTC-4, Michael Beller wrote:
You may be able to use jquery unwrap, wrap, or replace

For example, I want to load a component and not generate the wrapping DIV so I added a unique id to the top element in my view.load file and this inline at the bottom:
<script>
  $("#unique-id").unwrap();
</script>

You'd have to make sure that runs after the initial web2py.js handler that sets up the component, as that handler specifically looks for divs.

Anthony
Reply all
Reply to author
Forward
0 new messages