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

Commit

Permalink
- Fixing wrong up
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Apr 5, 2017
1 parent fb061d9 commit 8eaf12a
Show file tree
Hide file tree
Showing 19 changed files with 88 additions and 2,168 deletions.
11 changes: 5 additions & 6 deletions bower.json
@@ -1,13 +1,12 @@
{
"name": "ipub-form-phone",
"description": "Forms control for adding phone filed for Nette Framework",
"keywords": ["nette", "form", "phone", "ipub", "ipublikuj", "framework", "tools"],
"name": "ipub-form-slug",
"description": "Forms control for adding slug filed for Nette Framework",
"keywords": ["nette", "form", "slug", "ipub", "ipublikuj", "framework", "tools"],
"main": [
"public/js/ipub.formPhone.js"
"public/js/ipub.formSlug.js"
],
"dependencies": {
"jquery": "~2.1.0",
"ipub-phone": "^1.2.0"
"jquery": "~2.1.0"
},
"authors": [
{
Expand Down
18 changes: 8 additions & 10 deletions composer.json
@@ -1,9 +1,9 @@
{
"name" : "ipub/form-phone",
"name" : "ipub/form-slug",
"type" : "library",
"description" : "Forms control for adding phone filed for Nette Framework",
"keywords" : ["nette", "form", "phone", "ipub", "ipublikuj", "framework", "tools"],
"homepage" : "https://github.com/iPublikuj/form-phone",
"description" : "Forms control for adding slug filed for Nette Framework",
"keywords" : ["nette", "form", "sluggable", "ipub", "ipublikuj", "framework", "tools"],
"homepage" : "https://github.com/iPublikuj/form-slug",
"license" : ["GPL-2.0", "GPL-3.0"],

"authors": [
Expand All @@ -14,15 +14,13 @@
}
],

"support": {
"support":{
"email" :"support@ipublikuj.eu",
"issues" :"https://github.com/iPublikuj/form-phone/issues"
"issues" :"https://github.com/iPublikuj/form-slug/issues"
},

"require": {
"php" : ">=7.0.0",

"ipub/phone" : "~1.2",
"php" : ">=7.0",

"nette/application" : "~2.3@dev",
"nette/di" : "~2.3@dev",
Expand All @@ -46,7 +44,7 @@

"autoload": {
"psr-0": {
"IPub\\FormPhone\\": "src/"
"IPub\\FormSlug\\": "src/"
}
}
}
100 changes: 42 additions & 58 deletions docs/en/index.md
@@ -1,26 +1,26 @@
# Quickstart

This extension extend your [Nette](http://nette.org) forms with phone control field with specific phone number validation, based on [iPublikuj:Phone!](https://github.com/iPublikuj/phone)
This extension extend your [Nette](http://nette.org) forms with slug control field with automatic slug creation based on selected fields.

## Installation

The best way to install ipub/form-phone is using [Composer](http://getcomposer.org/):
The best way to install ipub/form-slug is using [Composer](http://getcomposer.org/):

```sh
$ composer require ipub/form-phone
$ composer require ipub/form-slug:@dev
```

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

```neon
extensions:
formPhone: IPub\FormPhone\DI\FormPhoneExtension
formSlug: IPub\FormSlug\DI\FormSlugExtension
```

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

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

Expand All @@ -29,86 +29,70 @@ note: You have to upload static files from **client-site** folder to your projec
## Usage

```php
$form->addPhone('phone', 'Phone number:');
$form->addSlug('slug', 'Slug:');
```

This control return values as normal text input, so you can access your phone like this:
You can connect other text inputs to this field and activate auto-generation slug, for example from item name:

```php
$phone = $form->values->phone;
```

Returned value is instance of IPub\Phone\Entities\Phone or null if the given phone number is not valid.

This control will render two elements, one select box where you can choose country prefix and one text box where you put your national part of number.
$form->addText('name', 'Name:')

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

Field can be validated as usual text fields in nette, but phone number can be validated with custom validator:
You can add more than one field:

```php
$form->addPhone('phone', 'Phone number:')
->addCondition(\Nette\Application\UI\Form::FILLED)
->addRule(\IPub\FormPhone\Forms\PhoneValidator::PHONE, 'Phone is invalid');
$form->addSlug('slug', 'Slug:')
->addField($form['name'])
->addField($form['subname']);
```

#### Limit to country

By default is country detection set to AUTO, if you want to specify allowed country/ies you can set them:
This control return values as normal text input, so you can acces your slug like this:

```php
$form->addPhone('phone', 'Phone number:')
->addAllowedCountry('CZ')
->addAllowedCountry('GB')
->addCondition(\Nette\Application\UI\Form::FILLED)
->addRule(\IPub\FormPhone\Forms\PhoneValidator::PHONE, 'Phone is invalid');
$slug = $form->values->slug;
```

or
### Validation

```php
$form->addPhone('phone', 'Phone number:')
->setAllowedCountries(['CZ', 'GB'])
->addCondition(\Nette\Application\UI\Form::FILLED)
->addRule(\IPub\FormPhone\Forms\PhoneValidator::PHONE, 'Phone is invalid');
```
Validation can be done as on usual text input, no changes are made here.

Now only phone numbers from Czech Republic or Great Britain are allowed.
### Custom templates and rendering

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

You can limit allowed phone to specific phone types eg. mobile, land line etc.
* bootstrap.latte if you are using [Twitter Bootstrap](http://getbootstrap.com/)
* uikit.latte if you are using [YooTheme UIKit](http://getuikit.com/)
* default.latte for custom styling (this template is loaded as default)

```php
$form->addPhone('phone', 'Phone number:')
->addAllowedPhoneType(\IPub\Phone\Phone::TYPE_MOBILE)
->addCondition(\Nette\Application\UI\Form::FILLED)
->addRule(\IPub\FormPhone\Forms\PhoneValidator::PHONE, 'Phone is invalid');
```
You can also define you own template if you need to fit this control into your layout.

or
Template can be set in form definition:

```php
$form->addPhone('phone', 'Phone number:')
->setAllowedPhoneTypes([\IPub\Phone\Phone::TYPE_MOBILE, \IPub\Phone\Phone::TYPE_PAGER])
->addCondition(\Nette\Application\UI\Form::FILLED)
->addRule(\IPub\FormPhone\Forms\PhoneValidator::PHONE, 'Phone is invalid');
$form->addSlug('slug', 'Slug:')
->setTemplateFile('path/to/your/template.latte');
```

List of allowed phone types is available in [iPublikuj:Phone!](https://github.com/iPublikuj/phone/blob/master/src/IPub/Phone/Phone.php#L39-L47)
or in manual renderer of the form:

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

Phone field can be rendered as usual, or manually with partial rendering:
and if you want to switch default template to **bootstrap** or **uikit** just it write into template setter:

```html
{form yourFormWithPhoneField}
// ...
```php
$form->addSlug('slug', 'Slug:')
->setTemplateFile('bootstrap.latte');
```

{label phone /}
{input phone:country}
{input phone:number}
or

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

0 comments on commit 8eaf12a

Please sign in to comment.