I have tried to find the cause of this issue, and believe it occurs due to
the fact that A is a subclass of DIV.
The ```isinstance(link, DIV)``` test then evaluates to True when ```link```
is an object of type A.
I could not find an option to change the behaviour of ```isinstance()```
and resorted to changing the following lines in html.py
diff --git a/gluon/html.py b/gluon/html.py
index 4adf287c..180f39a4 100644
--- a/gluon/html.py
+++ b/gluon/html.py
@@ -2526,14 +2526,16 @@ class MENU(DIV):
ul.append(item)
else:
(name, active, link) = item[:3]
- if isinstance(link, DIV):
+ if isinstance(link, DIV) and not isinstance(link, A):
li = LI(link)
elif 'no_link_url' in self.attributes and
self['no_link_url'] == link:
li = LI(DIV(name))
elif isinstance(link, dict):
li = LI(A(name, **link))
- elif link:
+ elif link and not isinstance(link, A):
li = LI(A(name, _href=link))
+ elif link and isinstance(link, A):
+ li = LI(name, link)
elif not link and isinstance(name, A):
li = LI(name)
else:
(END)
On Thursday, 7 June 2018 11:55:05 UTC+2, Rakesh Singh wrote:
>
> Hello,
>
> I have been trying to add external links to the menu system, but they
> result in malformed or invalid URL's when setting the target attribute.
> There are some old posts in the group regarding this, but none of the
> suggestions have worked.
>
> Web2py version : 2.16.1-stable
>
> Example:
> response.menu += [
> ('External Links', False, '#', [
> ('Icinga', False, URL('icinga'), []),
> # Works
> # SRC: <a class="dropdown-item"
> href="/Rakesh_Singh/default/icinga">Icinga</a>
> ('Google', False, google, []),
> # Works
> # SRC: <a class="dropdown-item" href="https://www.google.com
> ">Google</a>
>
> # Change target...
> ('', False, A('Icinga', _href=URL('icinga'), _target="_blank"),
> []),
> # Does not work; Menu item displays "Icinga\n>"
> # SRC: <a class="dropdown-item" href="<a
> href="/Rakesh_Singh/default/icinga" target="_blank">Icinga</a>"></a>
>
> ]
> )
> ]
>
>
> I have added a 'dirty' workaround in my layout.html that changes the
> target to '_blank' if the URL contains the string 'http'
>
> <div class="dropdown-menu">
> {{for _subitem in _item[3]:}}
> {{if _subitem[2].__contains__('http'):}}
> {{_target = '_blank'}}
> {{_rel = 'noopener'}}
> {{else:}}
> {{_target = '_self'}}
> {{_rel = 'preconnect '}}
> {{pass}}
> <a class="dropdown-item" href="{{=_subitem[2]}}"
> target="{{=_target}}" rel="{{=_rel}}">{{=_subitem[0]}}</a>
>
>
> Is there something incorrect in my code when specifying the target?
>
> Thank you.
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.