/** * @param Nette\Forms\Controls\UploadControl $control * @param $extensions * @return bool */ public static function validateExtension(Nette\Forms\Controls\UploadControl $control, $extensions) { $extensions = is_array($extensions) ? $extensions : explode(',', $extensions); foreach (static::toArray($control->getValue()) as $file) { /** @var Nette\Http\FileUpload $file */ $extension = strtolower(pathinfo($file->getSanitizedName(), PATHINFO_EXTENSION)); if (!in_array($extension, $extensions)) { return FALSE; } } return TRUE; }
/** * Is file image? * @return bool */ public static function validateImage(Controls\UploadControl $control) { foreach (static::toArray($control->getValue()) as $file) { if (!$file->isImage()) { return FALSE; } } return TRUE; }
public function getControl() { $control = Html::el(); if ($this->multi) { for ($i = 0; $i < 20; $i++) { $parent = parent::getControl(); $parent->name .= '-' . $i; $parent->onChange = 'if($(this).val()) { $("#' . $parent->id . '-' . ($i + 1) . '").parent().show(); }'; $parent->id .= '-' . $i; $control->add($d = Html::el('div')); $d->add($parent); if ($i > 0) { $d->style = 'display: none;'; } } } else { $control->add(parent::getControl()); } if ($this->fileEntity) { if ($this->multi) { $files = $this->fileEntity; } else { $files = array(); if ($this->fileEntity) { $files[] = $this->fileEntity; } } $div = $control->create('div', array('style' => 'margin: 5px 0;')); foreach ($files as $file) { $div2 = $div->create('div', array('style' => 'float: left; margin-right: 10px;', 'class' => 'caption')); $div2->create('img', array('src' => $file->getFileUrl(), 'style' => 'height: 64px; width: 64px;', 'class' => 'img-polaroid img-rounded')); $div2->create('br'); $div2->create('input', array('type' => 'checkbox', 'name' => $this->name . '_delete_' . $file->id)); $div2->create('span')->setText(' ' . ($this->translator ? $this->translator->translate('delete') : 'delete')); } } return $control; }
public function validate() { if (!$this->isValidated) { parent::validate(); } }
/** * Image validator: is file image? * @param UploadControl * @return bool */ public static function validateImage(UploadControl $control) { $file = $control->getValue(); return $file instanceof Http\FileUpload && $file->isImage(); }
/** * Generates control's HTML element. */ public function getControl() { $input = parent::getControl(); if ($this->path) { $this->template->pathName = $this->getHtmlName() . "-path"; $this->template->path = $this->path; $this->template->setFile(__DIR__ . "/templates/edit.latte"); } else { $this->template->setFile(__DIR__ . "/templates/add.latte"); } $this->template->removedName = $this->getHtmlName() . "-removed"; $this->template->input = $input; $this->template->_form = $this->getForm(); return Html::el()->add((string) $this->template); }
/** * @param UploadControl $control * @return bool */ public static function validateImage(UploadControl $control) { $files = $control->getValue(); foreach ($files as $file) { if (!($file instanceof Http\FileUpload && $file->isImage())) { return FALSE; } } return TRUE; }
/** * Získání identifikačního tokenu. */ public function loadHttpData() { parent::loadHttpData(); $request = $this->getContainer()->getByType('\\Nette\\Http\\Request'); /** @var \Nette\Http\Request $request */ $this->token = $request->getPost($this->getHtmlName() . "-token"); }
FALSE;}static function validateImage(UploadControl$control){$file=$control->getValue();return$file instanceof Http\FileUpload&&$file->isImage();}}}namespace Nette\Forms\Rendering{use
/** * FileSize validator: is file size in limit? * @param Forms\Controls\UploadControl * @param int file size limit * @return bool */ public static function validateFileSize(Forms\Controls\UploadControl $control, $limit) { $files = $control->getValue(); $size = 0; foreach ($files as $file) { $size += $file->getSize(); } return $size <= $limit; }
public function register(array $messages = []) { if ($this->registered) { return; } // Default error messages for custom validators foreach ($messages as $validator => $message) { Nette\Forms\Rules::$defaultMessages[$validator] = $message; } // addLinkSubmit Container::extensionMethod('addLinkSubmit', function (Container $container, $name, $label = NULL, $icon = NULL, $destination = NULL) { $control = new Zax\Forms\Controls\LinkSubmitButton($label); $proto = $control->getControlPrototype(); $proto->href($destination); $proto->setHtml($this->makeLabel($this->translate($label), $icon)); return $container[$name] = $control; }); // addButtonSubmit Container::extensionMethod('addButtonSubmit', function (Container $container, $name, $label = NULL, $icon = NULL, $data = []) { $control = new Nette\Forms\Controls\SubmitButton($label); $proto = $control->getControlPrototype(); $proto->setName('button'); $proto->setType('submit'); foreach ($data as $key => $value) { $proto->setData($key, $value); } $label = $this->makeLabel($this->translate($label), $icon); $proto->setHtml($label); return $container[$name] = $control; }); // addTexyArea Container::extensionMethod('addTexyArea', function (Container $container, $name, $label = NULL) { $control = new Zax\Forms\Controls\TexyAreaInput($label); $control->injectIcons($this->icons); return $container[$name] = $control; }); // addFileUpload Container::extensionMethod('addFileUpload', function (Container $container, $name, $label = NULL, $multiple = FALSE) { $upload = new Nette\Forms\Controls\UploadControl($label, $multiple); $upload->getControlPrototype()->setData(['buttonText' => $this->translate('common.button.chooseFile' . ($multiple ? 's' : '')), 'input' => $multiple ? 'false' : 'true', 'maxFiles' => $multiple ? Zax\Utils\HttpHelpers::getMaxFileUploads() : 1]); $upload->addRule(Zax\Application\UI\Form::MAX_FILE_SIZE, NULL, Zax\Utils\HttpHelpers::getMaxUploadSize() * 1024 * 1024); return $container[$name] = $upload; }); // addEmail Container::extensionMethod('addEmail', function (Container $container, $name, $label = NULL, $cols = NULL, $maxLength = NULL) { $text = $container->addText($name, $label, $cols, $maxLength); $text->setType('email'); $text->addCondition(Nette\Forms\Form::FILLED)->addRule(Nette\Forms\Form::EMAIL); return $text; }); // addArrayTextArea Container::extensionMethod('addArrayTextArea', function (Container $container, $name, $label = NULL, $keyValDelimiter = NULL) { $control = new Zax\Forms\Controls\ArrayTextAreaControl($label, $keyValDelimiter); return $container[$name] = $control; }); // addNeonTextArea Container::extensionMethod('addNeonTextArea', function (Container $container, $name, $label = NULL) { $control = new Zax\Forms\Controls\NeonTextAreaControl($label); return $container[$name] = $control; }); // addStatic Container::extensionMethod('addStatic', function (Container $container, $name, $label = NULL) { $control = new Zax\Forms\Controls\StaticControl($label); return $container[$name] = $control; }); // addAutoComplete Container::extensionMethod('addAutoComplete', function (Container $container, $name, $label = NULL, $autocomplete = []) { $control = $container->addText($name, $label); $control->getControlPrototype()->addClass('jqueryui_autocomplete')->setData('autocomplete', $autocomplete); return $control; }); // addMultiAutoComplete Container::extensionMethod('addMultiAutoComplete', function (Container $container, $name, $label = NULL, $autocomplete = []) { $control = $container->addText($name, $label); $control->getControlPrototype()->addClass('jqueryui_multiautocomplete')->setData('autocomplete', $autocomplete); return $control; }); $this->registered = TRUE; }
public function getControl() { return parent::getControl()->multiple(TRUE); }
/** * @param string $caption * @return \Nette\Utils\Html|string */ public function getLabel($caption = NULL) { if ($this->checkbox->isOk()) { return $this->isRequired() ? parent::getLabel($caption) : NULL; } return parent::getLabel($caption); }