Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link requires protocol and gives no feedback (error message or otherwise) #44

Closed
adamschwartz opened this issue Oct 19, 2015 · 13 comments
Closed

Comments

@adamschwartz
Copy link

Repro steps: on http://trix-editor.org, select some regular text and click the link toolbar button. Type “example.com” and hit ENTER. Observe that nothing happens. Prepending “http://” and hitting ENTER does create the link.

If a protocol is required, this should be explained or something should happen. Otherwise, the experience just feels confusing and broken.

@philfreo
Copy link

👍

@Kapunk
Copy link

Kapunk commented Oct 23, 2015

I see the problem, the problem is the pattern, that is this:
matchingSelector = "a:not(#attachmentSelector})" in text_attributes.coffe

If you put a letter and then ":" always works. The pattern should be corrected

@tvanderpol
Copy link

I reproduced this when integrating Trix into a project of mine as well. Excellent project, btw - very easy to work with and does exactly what it says on the tin. 👍

@agraddy
Copy link

agraddy commented Nov 3, 2015

I think it's important to be able to create relative links. I was confused when testing the editor and tried entering "/contact-us" to see what happened and it wouldn't let me create a link.

@javan
Copy link
Contributor

javan commented Nov 3, 2015

The link input is an <input type="url"> and is validated by the browser natively. The lack of feedback for invalid URLs is a result of our default styles. I'll make sure to fix them up, and in the meantime you're free to override them in your app or not include them at all.

Firefox doesn't appear to be affected and correctly highlights the field as invalid:
screen shot 2015-11-03 at 5 21 20 pm

If you want to change the element to allow any input, you could change it to a text field:

input = Trix.config.toolbar.content.querySelector("input[type=url]")
input.type = "text"

Customizing the toolbar like this is undocumented currently because it's likely to change, but it should work fine for now.

@adamschwartz
Copy link
Author

@javan thx!

@javan
Copy link
Contributor

javan commented Nov 6, 2015

I fixed up the invalid link input styles in the latest release, 0.9.1.

screen shot 2015-11-06 at 3 50 04 pm

@javan javan closed this as completed Nov 6, 2015
@philfreo
Copy link

philfreo commented Nov 6, 2015

It's still bad UX for an editor to not allow someone to type something more friendly like google.com and have it auto-add the prefix.

@javan
Copy link
Contributor

javan commented Nov 6, 2015

@philfreo, totally agree. I'd be happy to review a PR that improves things.

@mitar
Copy link
Contributor

mitar commented Nov 12, 2015

What about using autolinker.js. It seems to work pretty fine.

Maybe even easier would be to make this a plugin which makes links automatically as you type. So through the toolbar you have to enter a precise URL. But if you enter it in the text, like type it in, it auto-links it.

@nhk-gh
Copy link

nhk-gh commented Apr 4, 2016

When link created: clicking on it do nothing! Its possible to open link only via browser menu (right mouse click)

@Laassari
Copy link

since Trix has changed the suggested fix no longer works (the feedback works fine). here's how I did it

const { toolbarElement } = event.target;
const urlInput = toolbarElement.querySelector('input[name=href]');

urlInput.type = 'text';

// Beware the double escape. since we pass regex as a string we have to double escape the backslashes 
urlInput.pattern = '^((?:https?:\\/\\/)?[^./]+(?:\\.[^./]{2,})+(?:\\/.*)?)$';

@frenkel
Copy link

frenkel commented Jul 6, 2022

In case somebody is interested. I'm using this to help the user and insert https:// for them:

function prependProtocol(urlField) {
  if(urlField.value.indexOf('http') != 0) {
    urlField.value = "https://" + urlField.value
  }
}
document.addEventListener('trix-initialize', event => {
  let linkButton = event.target.toolbarElement.querySelector('input[value="Link"]')
  let urlField = event.target.toolbarElement.querySelector('input[name="href"]')
  urlField.addEventListener('keydown', (e) => {
    if(e.key == 'Enter') {
      prependProtocol(urlField)
    }
  })
  linkButton.addEventListener('click', () => {
    prependProtocol(urlField)
  })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants