#1 October 10, 2012 6:21am

philp
Member
Registered: April 5, 2012
Posts: 25

Custom Field Types

Hi,


I'm currently looking at how to implement a custom field type, and I'm getting a little bit lost.


Basically, I'm trying to implement a new field type which uses the Redactor WYSIWYG editor as an alternative to the TinyMCE. My guess is that once I've created the new field type in the admin, I then need to do my magic in the files which are created, but I'm a bit unclear as to what each is responsible for, and where my custom JS should live, and the best way to hook it up.


Does anybody have any pointers or advice?

Offline

#2 October 10, 2012 8:55am

benplum
Administrator
Registered: March 30, 2012
Posts: 54

Re: Custom Field Types

This shouldn't be a problem, we've implemented custom editors in the past using plugins like Code Mirror.

When custom field types are made through the admin, a few files are created:

custom/admin/form-field-types/draw/your-field-id.php
custom/admin/form-field-types/draw/your-field-id.php
custom/admin/ajax/developer/field-options/your-field-id.php

The first and second files are where the heavy lifting happens, the last is in case you need to set custom options for the field (this file is loaded into the field options modal when editing a form in the developer area). If you take a look at the file for the built-in WYSIWYG (core/admin/form-field-types/draw/html.php) you'll notice that all it does is add the field's id to an array of WYSIWYG instances, then include the standard textarea field. The array is then used to initialize all instances based on their id. This is essentially what you'll be doing in each instance of the field:

Offline

#3 October 10, 2012 9:47am

philp
Member
Registered: April 5, 2012
Posts: 25

Re: Custom Field Types

Thanks so much Ben — that's a really comprehensive overview, and sounds really straightforward now you've explained it. Will give it a go!

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.