<commit_before><?php

namespace Octo\Form\Element;

use b8\View;
use b8\Form\Element\Upload;

class ImageUpload extends Upload
{
    /**
     * @var string ID of current image
     */
    protected $imageId;
    /**
     * @var string Whether to accept multiple elements
     */
    protected $multiple = '';

    /**
     * @param null $viewFile
     * @return string
     */
    public function render($viewFile = null)
    {
        return parent::render('ImageUpload');
    }

    /**
     * @param View $view
     */
    protected function onPreRender(View &$view)
    {
        parent::onPreRender($view);
        $view->type = 'file';
        $view->imageId = $this->imageId;
        $view->multiple = $this->multiple;
    }

    /**
     * @param $url
     */
    public function setImageId($url)
    {
        $this->imageId = $url;
    }

    /**
     * Sets the "multiple" property on the element to true
     */
    public function setMultiple()
    {
        $this->multiple = 'multiple';
    }
}<commit_msg>Fixing required error on multiple file upload fields.<commit_after><?php

namespace Octo\Form\Element;

use b8\View;
use b8\Form\Element\Upload;

class ImageUpload extends Upload
{
    /**
     * @var string ID of current image
     */
    protected $imageId;
    /**
     * @var string Whether to accept multiple elements
     */
    protected $multiple = '';

    /**
     * @param null $viewFile
     * @return string
     */
    public function render($viewFile = null)
    {
        return parent::render('ImageUpload');
    }

    /**
     * @param View $view
     */
    protected function onPreRender(View &$view)
    {
        parent::onPreRender($view);
        $view->type = 'file';
        $view->imageId = $this->imageId;
        $view->multiple = $this->multiple;
    }

    /**
     * @param $url
     */
    public function setImageId($url)
    {
        $this->imageId = $url;
    }

    /**
     * Sets the "multiple" property on the element to true
     */
    public function setMultiple()
    {
        $this->multiple = 'multiple';
    }


    public function validate()
    {
        $multipleFilesUploaded = false;
        if (strval($this->multiple) != '') {
            $field = str_replace('[]', '', $this->name);
            if (isset($_FILES[$field]['name'][0]) && strlen($_FILES[$field]['name'][0]) > 0) {
                $multipleFilesUploaded = true;
            }
        }

        if ($this->getRequired() && !$multipleFilesUploaded && (is_null($this->value) || $this->value == '')) {
            $this->error = $this->getLabel() . ' is required.';
            return false;
        }

        if ($this->getPattern() && !preg_match('/' . $this->getPattern() . '/', $this->value)) {
            $this->error = 'Invalid value entered.';
            return false;
        }

        $validator = $this->getValidator();

        if (is_callable($validator)) {
            try {
                call_user_func_array($validator, array($this->value));
            } catch (\Exception $ex) {
                $this->error = $ex->getMessage();
                return false;
            }
        }

        if ($this->customError) {
            return false;
        }

        return true;
    }
}
{'fraction_non_alphanumeric': 0.15161787365177196, 'fraction_numerical': 0.0021571648690292757, 'mean_word_length': 1.852372583479789, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7638225', 'n_tokens_mistral': 961, 'n_tokens_neox': 942, 'n_words': 213}