Using-custom-field-of-jform-create-textcounter-1

Joomla already has powerful form management libraries - jform, supported by jfield. There is plenty of built-in field types (text, textarea, integer, file, calendar and several more). However, once in a while you come across a special field that is not present. Or maybe extending the existing field types to add more features.

These are perfect candidates for creating your own JFields. The JField class is very easy to understand, and using the same you can create any kind of simple or complex fields. Bear in mind that while the JField class will render your field, it's up to your model to save the data.

In a recent project, I had to create a text field with a character limit and a  character counter. My earlier thought was to include a piece of javascript, but I soon realized that this was a good opportunity to create a reusable field which supports the above. So today I will be explaining how to create your own JFields through an example of the character counter field.

So let's start to create the field which will add the character counter for the simple text field

Step 1: Create new field type PHP file in your component folder. (components/your_component/models/fields/textcounter.php)

You can do this with Textarea also, just by replacing the code accordingly. You can find this all code here. Big thanks to Ashwin for the git hub repo.

What kind of fields have you created with JField? Did you face any issues? Need any help with your fields, do share feedback below!

Let me know your thoughts in comments!

Suggestions/Corrections are Most welcome!