Jump to content

Inputfield Hook


Recommended Posts


i want to replace {meta_id} with $Inputfield->name. But not works as expected.  {meta_id} replaced with parent "Fieldset" or "Form" name.

$wire->addHookBefore('InputfieldWrapper::render', function ($event) {
    $wrapper = $event->object;

        'item_content' => "<div class='InputfieldContent uk-form-controls {class}'>{out}</div><div id="{meta_id}" class='uk-form-controls-meta'>{error}{description}{notes}</div>",
$wire->addHookAfter('Inputfield::render', function (HookEvent $event) {
    $Inputfield = $event->object;
    $return = $event->return;

    $return = str_replace("{meta_id}", $Inputfield->name, $return);

    // Populate back return value, if you have modified it
    $event->return = $return;


Link to comment
Share on other sites

Yes, that is because of the order in which ProcessWire executes its steps when it renders a form. While your template is used for every Inputfield contained in an InputfieldWrapper, each Inputfield's render method is called individually inside InputfieldWrapper::render first, then its rendered return value is then inserted into the item_content template in place of {out}. So the Inputfield doesn't even get to see the template.

The "strange" behavior comes up because the surrounding InputfieldWrapper, often an InputfieldForm that extends it, also extends Inputfield and is the last (outermost, as we are talking about recursion) time the render() hook is invoked, this one finally with all the rendered item_content parts that still have the literal {meta_id} strings.

Not sure how to accomplish what you're trying to without jumping through some complicated hoops.

  • Like 2
Link to comment
Share on other sites

Using unpoly for last project needs to validate checkboxes. Normaly unpoly replace input parent .Inputfield div. When user checks fast input seems unresponsive because unpoly replace .Inputfield's content. So i need to inputfield's specific div to replace. 

Added custom div but unpoly still ignore selector for radios and checkboxes. I tried to solve the problem but the problem was unpoly

<input type="text" name="email" up-validate=".email-errors">
<span class="email-errors"></span>


$wire->addHookAfter('InputfieldForm::render', function (HookEvent $event) {
    // Get the object the event occurred on, if needed
    $InputfieldForm = $event->object;

    // An 'after' hook can retrieve and/or modify the return value
    $return = $event->return;

    $doc = new \DOMDocument();
    $doc->loadHTML(mb_convert_encoding($return, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NODEFDTD);
    $xpath = new \DOMXPath($doc);

    $nodeList = $xpath->query("//div[@class='uk-form-controls-meta']");

    foreach ($nodeList as $key => $node) {
        $parentID = $node->parentNode->getAttribute('id');
        $parentID = str_replace("wrap_Inputfield_", "", $parentID);
        $parentID = $parentID . "_error";

        $node->setAttribute("class", $parentID);

    $return = $doc->saveHTML();

    $return = renderNotices() . $return;

    $event->return = $return;


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...