Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

Latest commit

 

History

History
119 lines (83 loc) · 2.97 KB

readme.md

File metadata and controls

119 lines (83 loc) · 2.97 KB

Form Slug control

Build Status Latest Stable Version Composer Downloads

Forms control for adding slug filed for Nette Framework

Installation

The best way to install ipub/form-slug is using Composer:

{
	"require": {
		"ipub/form-slug": "dev-master"
	}
}

or

$ composer require ipub/form-slug:@dev

After that you have to register extension in config.neon.

extensions:
	formSlug: IPub\FormSlug\DI\FormSlugExtension

In Nette 2.0, registration is done in app/bootstrap.php:

$configurator->onCompile[] = function ($configurator, $compiler) {
	$compiler->addExtension('formSlug', new IPub\FormSlug\DI\FormSlugExtension);
};

And you also need to include static files into your page:

	<script src="{$basePath}/libs/ipub.formSlug.js"></script>
</body>

note: You have to upload static files from client-site folder to your project.

Usage

$form->addSlug('slug', 'Slug:');

You can connect other text inputs to this field and activate auto-generation slug, for example from item name:

$form->addText('name', 'Name:')

$form->addSlug('slug', 'Slug:')
	->addField($form['name']);

You can add more than one field:

$form->addSlug('slug', 'Slug:')
	->addField($form['name'])
	->addField($form['subname']);

This control return values as normal text input, so you can acces your slug like this:

$slug = $form->values->slug;

Validation

Validation can be done as on usual text input, no changes are made here.

Custom templates and rendering

This control come with templating feature, that mean form element of this control is rendered in latte template. There are 3 predefined templates:

  • bootstrap.latte if you are using Twitter Bootstrap
  • uikit.latte if you are using YooTheme UIKit
  • default.latte for custom styling (this template is loaded as default)

You can also define you own template if you need to fit this control into your layout.

Template can be set in form definition:

$form->addSlug('slug', 'Slug:')
	->setTemplateFile('path/to/your/template.latte');

or in manual renderer of the form:

{?$form['slug']->setTemplateFile('path/to/your/template.latte')}
{input slug class => "some-custom-class"}

and if you want to switch default template to bootstrap or uikit just it write into template setter:

$form->addSlug('slug', 'Slug:')
	->setTemplateFile('bootstrap.latte');

or

{?$form['slug']->setTemplateFile('bootstrap.latte')}
{input slug class => "some-custom-class"}