JReviews logo Docs
Menu
Version

field_form{:name|:type}

Allows modifying custom field input properties before these are converted into HTML form elements.

Filter
Custom Fields
Since 3.10.0

You need to have a working knowledge of Hooks before you get started.

There are three variations for this filter, universal for all fields, and field-name-specific, and field-type specific:

  • field_form
  • field_form:jr_status
  • field_form:select

The filters run in the same order listed above.

Parameters

Name Type Description
$input parameter (array) input properties
$field parameter (array) custom field settings

Boilerplate Code

Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.

Clickfwd\Hook\Filter::add('field_form-name-or-type', function($input, $field)
{
    // Uncomment line below to view available data passed into hook
    // fwd_dd($input, $field);

    return $input;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.

Examples

Limit text length using `maxlength` attribute

The ability to add attributes to custom field inputs can be quite useful. For example, say you have a listing custom field named `jr_description` where you want to limit the number of characters to 50. The following filter does the job: <br> ```php Clickfwd\Hook\Filter::add('field_form:jr_description', function($input, $field) { $input['maxlength'] = 50; return $input; }); ``` This only adds client-side validation in the browser. To also add sever validation you can update the field's regex setting with the following value: <br> ```bash ^.{1,50}$ ``` If you also want to add a character counter to the input, you can do that with the following code: <br> ```php Clickfwd\Hook\Action::add('form:data.field.listing.jr_description:before', function($options) { echo '<div class="fwd-mb-3" x-data="{ maxChars: 50, currentChars: 0, updateUsedChars() { this.currentChars = event.target.value.length; } }" x-on:input="(event) => updateUsedChars(event)" >'; }); Clickfwd\Hook\Action::add('form:data.field.listing.jr_description:after', function($options) { echo '<p x-text="`${currentChars}/${maxChars} characters`" x-bind:class="currentChars > maxChars && \'fwd-text-red-600\'" style="margin-top: -0.75rem;" ></p>'; echo '</div>'; }); ```


Source Files

  • /views/helpers/custom_fields.php