1

ers:

I want to open a record from a list view on a new tab.

I tried making a computed char field making an URL and put a widget="url" but it put the whole link as a text making the cell too big. So I just want an icon like 🔗 that opens the record in a new tab or the user can copy the link by right click.

1 Answer 1

1

Here is what worked for me.

  1. Make a computed HTML field with building the link like this:
link = fields.Html(compute='_compute_link')

def _compute_link(self):
   for rec in self:
      rec.link = f"""<a href="/mail/view?model={self._name}&res_id={rec.id} target="_blank"><i class="oi oi-launch" onclick="event.stopPropagation()"/></a>"""
  1. Put the field widget HTML on the list view.

<field name="link" nolabel="1"/>

Notes:

  • I'm using /mail/view the same as a link is given on notification emails, avoid putting action id since it can change over every DB/code.
  • If you don't include stop propagation on the link, it will open the record on that tab (as expected click on the cell).
Sign up to request clarification or add additional context in comments.

4 Comments

Normally I leave it up to the user how he wants to deal with a link or a URL. My tool of choice is the middle mouse button (greetings to Apple users). Apart from that, a tip for your implementation: Use an HTML field right away, then you don't need to use the widget in the view.
I considered it, I think making an HTML field would create jsonb columns on the table, I don't think it is needed since a simple varchar is enough
I meant, if you go for storing the field.
No, translatable fields are using jsonb in database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.