Jump to content

techweek

Starter
  • Posts

    1
  • Joined

  • Last visited

Posts posted by techweek

  1. That was brilliant! thank you for this

    On 10/1/2017 at 11:59 PM, Robin S said:

    Suppose you have an images field and you want editors to upload a specific number of images to that field.

    Using a hook in /site/ready.php you can display a field error in Page Edit if the number of images in the field does not match the required number. Just like the standard "required" behaviour, the requirement does not prevent the field being saved if the number of images is not correct so you would still want to check the image count in your template.

    
    $wire->addHookAfter('InputfieldImage::processInput', function(HookEvent $event) {
        $inputfield = $event->object;
        // Only for this field
        if($inputfield->hasField != 'images') return;
        // Only in ProcessPageEdit
        if($this->process != 'ProcessPageEdit') return;
        $page = $this->process->getPage();
        // Only for this template
        if($page->template == 'home') {
            if(count($inputfield->value) !== 4) $inputfield->error("Please upload exactly 4 images to this field");
        }
    });

     

    That was brilliant, thank you for this

×
×
  • Create New...