harvard-lil / h2o

H2O is a web app for creating and reading open educational resources, primarily in the legal field
https://opencasebook.org
GNU Affero General Public License v3.0
36 stars 30 forks source link

Limit text input to appropriate URL types #1987

Closed lizadaly closed 1 year ago

lizadaly commented 1 year ago

If the user selects type Link or Clone (a Clone is a link to another H2O resource), change the input type to url and let the browser validate.

For type Clone, applies the pattern attribute with the current origin so the browser handles client-side validation. (This pattern matches the internal check on whether a link is considered external or a clone.)

In Chrome and Firefox, the browser will make use of the title attribute to hint to the user what the required pattern is. In Safari, naturally, the validation is enforced but the pattern is not displayed. (This is impossible to screenshot.)

With some custom validation we could make this experience a little nicer, but this is almost all declarative markup and very much an edge case. If the user somehow blows past the client-side validation, they'll get the server-side error from #1985 anyway, rather than no response.