Download the PHP package alb/fselectmenu without Composer
On this page you can find all versions of the php package alb/fselectmenu. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download alb/fselectmenu
More information about alb/fselectmenu
Files in alb/fselectmenu
Package fselectmenu
Short Description Fast and non-intrusive HTML select menu
License MIT
Homepage https://github.com/arnaud-lb/fselectmenu
Informations about the package fselectmenu
FSelectMenu
FSelectMenu is a Fast and non-intrusive HTML select menu.
Features:
-
Fast: rendering is done on the server side: no DOM manipulation on the client side
-
Non intrusive: Once FSelectMenu is initialized you can forget it: every select menu will work, whether they were present during initialization or added later. (FSelectMenu uses event delegation. The HTML code is generated on the server; all that is left to FSelectMenu is to listen for events bubbling to the document element.).
- Non intrusive: Works out of the box with existing scripts
- Scripts don't have to know anything about FSelectMenu for simple things like listening for events, getting and changing the value, etc.
- Scripts interact with the native select element directly
Usage
Load and init the FSelectMenu javascript module:
That's all.
If you add new select menus on the document after that, you don't have to call .init()
again.
Just trigger the change
event on the native select element when programmatically changing its value.
Install
Plain PHP
You can render a FSelectMenu with the FSelectMenu\Renderer class:
- $value is the value of the selected choice
- $choices is an array of value => label choices (with nested arrays, for optgroups)
- $options is an array with the following keys:
- attrs: fselectmenu element attributes (e.g. id, class, ...)
- nativeAttrs: native select element attributes (e.g. id, name)
- optionAttrs: choice elements attributes (array of value => attributes)
- optionWrapperAttrs: choice elements wrapper attributes
- rawLabels: whether to escape labels
- fixedLabel: a label that will always be displayed instead of the selected label
Example:
Twig
Register the extension:
The extension exposes the fselectmenu
method:
fselectmenu(value, choices, options)
See Plain PHP above for a description of the parameters.
Example:
Javascript
Menus can also be rendered in Javascript (e.g. on the client side or in nodejs) with the renderer
module:
Symfony2
Add the FSelectMenu namespace to your autoloader
Add FSelectMenuBundle to your application kernel
Overload the choice_widget
block in your form theme:
ZendFramework
Register view helper path:
Subclass Zend_Form_Element_Select:
Styling
FSelectMenu comes with a minimal (behavior only) stylesheet at lib/FSelectMenu/Bundle/Resources/sass/_fselectmenu.sass
.
Graceful degradation
Support for clients without javascript enabled can be achieved by hidding the fake select menu and displaying the native one: