Coder Social home page Coder Social logo

nette-forms-inputlist's Introduction

For Nette Framework

Alternative RadioList & CheckboxList for Nette Framework

License

New BSD

Dependencies

Nette 2.0.0

Installation

  1. Get the source code from Github or via Composer (vojtech-dobes/nette-forms-inputlist).
  2. Register VojtechDobes\NetteForms\InputListExtension as extension for $configurator.
$configurator->onCompile[] = function ($configurator, $compiler) {
	$compiler->addExtension('inputlist', new VojtechDobes\NetteForms\InputListExtension);
};

Usage

RadioList

$form->addMultiRadio('sex', 'Sex:', array(
	'male' => 'Male',
	'female' => 'Female',
));

Method's name was chosen to not interfere with native addRadiolist.

CheckboxList

$checkboxlist = $form->addMultiCheckbox('topics', 'I like:', array(
	'l' => 'lifestyle',
	'm' => 'military',
	'c' => 'computers',
	'f' => 'flowers',
));
Defaults
$checkboxlist->setDefaultValue(array('l', 'm')); // lifestyle, military
Returned values
$checkboxlist->getValue() === array(0 => 'l', 1 => 'm')

Rendering

Automatic

Both RadioList and CheckboxList provide standard mechanism like getControlPrototype etc. You can also force omitting of last separator:

$radiolist->omitLastSeparator();

Manual

There is special new macro for Latte templates: {inputlist}. It behaves exactly like {foreach}, but it's specifically design to work with *List form elements.

{form formName}
	{inputlist sex as $key => $label}
		{input} {label /} {sep}<br>{/sep}
	{/inputlist}
{/form}

Macros {input} and {label} behave the same way as always, but when used without element identificator, they will render proper elements for iteration specific item. If you use it with identificator, it will render appropriate element from form.

{form formName}
	{inputlist sex as $key => $label}
		{input} {label /}<br>
		{input send} {* standard button, no problem *}
	{/inputlist}
{/form}

You can add HTML attributes to them as usually.

{form formName}
	{inputlist sex as $key => $label}
		{input class => 'input-radio'} {label}{$label}{/label}<br>
	{/inputlist}
{/form}

Attribute version of {inputlist} is also possible:

{form formName}
	<ul n:inner-inputlist="sex as $key => $label">
		<li>{input} {label /}</li>
	</ul>
{/form}

Validation

Here supported rules are listed:

CheckboxList

Form::FILLED At least one box must be checked.
Form::LENGTH Exact amount of boxes that must be checked.
Form::MIN_LENGTH Minimum amount of boxes that must be checked.
Form::MAX_LENGTH Maximum amount of boxes that must be checked.
Form::RANGE Minimum and maximum amount of boxes that must be checked.
Form::REGEXP Checks if selected checkbox values match regular expression.

RadioList

Form::FILLED One button must be selected.
Form::REGEXP Checks if selected radio value matches regular expression.

All rules are also supported on client-side.

nette-forms-inputlist's People

Contributors

enumag avatar jasir avatar tivvit avatar uestla avatar vojtech-dobes avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.