Jump to content

URL button in form


rick
 Share

Recommended Posts

How do I place a button next to the URL text field on a form created from the API?

I have the following code to create the text field to display on the form and it works as expected. This text field contains a URL. I want to place a button next to this field that will open the URL in another tab.

$field = $this->wire('modules')->get("InputfieldText");
$field->attr('id+name', 'some_link');
$field->title = "Link";
$field->label="Some Link";
$field->columnWidth = 50;
$field->value = $this->some_link;
$wrapper->add($field);

The result of what I want is this:

[ some_link         ] [ view ]

where the view button opens the URL in a different tab.

Can someone offer some insight?

Link to comment
Share on other sites

3 hours ago, rick said:

I want to place a button next to this field that will open the URL in another tab.

You could add the link with jQuery. 

  • select your DOM (input: some_link) element
  • append the link to the previous selected element: $('#some_link').append('<a href="#" id="view-link">view</a>')
  • use the click event to open the url :   $('#view-link').on('click', function(e) { window.open($('#some_link').val(), '_blank'); });

something like that...

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...