GithubHelp home page GithubHelp logo

Comments (13)

frenkel avatar frenkel commented on August 28, 2024 3

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)
  })
})

from trix.

agraddy avatar agraddy commented on August 28, 2024 1

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.

from trix.

javan avatar javan commented on August 28, 2024 1

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.

from trix.

philfreo avatar philfreo commented on August 28, 2024

👍

from trix.

Kapunk avatar Kapunk commented on August 28, 2024

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

from trix.

tvanderpol avatar tvanderpol commented on August 28, 2024

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. 👍

from trix.

adamschwartz avatar adamschwartz commented on August 28, 2024

@javan thx!

from trix.

javan avatar javan commented on August 28, 2024

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

from trix.

philfreo avatar philfreo commented on August 28, 2024

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.

from trix.

javan avatar javan commented on August 28, 2024

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

from trix.

mitar avatar mitar commented on August 28, 2024

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.

from trix.

nhk-gh avatar nhk-gh commented on August 28, 2024

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

from trix.

Laassari avatar Laassari commented on August 28, 2024

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,})+(?:\\/.*)?)$';

from trix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.