Content Type definition, javascript field, evaluation in admin

Hi,

We had requests to implement per content field functionality in admin.
Would be great to be able to implement a field in the content-type definition to run browser js in admin (or more scopes, like page render, new object, editing etc.).
For example:

<input name="preface" type="TextArea">
<label>Preface</label>
<on-admin-edit-js>$(this).onChange(function(input){autocomplete(input)});</admin-edit-js>
<on-render-js>$(this).onLoad(function(){showTooltip()});</on-render-js>
</input>

Or adding a backend js that would be able to modify HTML tags, this.element.addAttribute(adminScope, ‘onChange’, ‘javascriptOnChange()’).

A hack is to do it in greasemonkey but it’s troublesome to update it for all editors in a corporation.

1 Like

It would be possible to use this to implement features like this one, maybe with a set of predefined scripts:
https://discuss-3.enonic.com/t/limit-number-of-characters-in-textline-and-textarea/1039

What you are looking for is making yor own custom input types. This has been in our plans since we started building XP.

Thing is, input types have both a front-end and server-side implementation, handling validation etc, etc. Also there is a lot of documentation related to admin css and coding to ensure 3rd party code will run smoothly in all scenarios.

I guess if one could “extend” or simply use the back-end of an existing input-type it would at least limit the work to front-end only.

For this part I would say extending the data-types with a bunch of javascript injection points, that would target the unique ID of each field and insert the frontend javascript targeting that field.
Also a external javascript source would be needed, like:

<content-type>
  <display-name>Article</display-name>
  <require-js>dependency1.js</require-js>
  <require-js>dependency2.js</require-js>
...
</content-type>

Basically the definition of the injection points could be:
(prefix)-(scope)-(trigger)
<on-admin-onchange>function(event){showCount(event)}</on-admin-onchange>
where a field with name ‘header’ would get a javascript, jquery style just as an example:
$( "input[name='header-0']" ).onChange(function(event){showCount(event)})

Sure, backend bit with validation would be great too :slight_smile:

@tsi my client is asking if we have an estimate, so I thought maybe a babystep solution to just be able to add a frontend .js dependency (<script> include) in all admin pages (or just the editor) would be sufficient to implement a minimum solution. Is there any way to do it inside an app?

Hi again!

We have discussed this. As we are concerned with backward compatiblility as new versions of XP are released, adding custom javascript in the current content editor is a no-go on our side. It might sound tempting but is in the end a road to customer dissatisfaction. The details on how the Content Studio client works at the moment are not documented, and the technical details may change for every minor release.

As custom input types are already in our backlog, and will provide a supported and predictable way of building input, the only way you can get a quick-fix for what you are looking for is requesting specific requirements you might have for inputs. We are easily able to improve the standard input types, and even create new ones if the requirement is generic.