Coder Social home page Coder Social logo

yii2-widgets's Introduction

Krajee Logo
yii2-widgets
Donate

Stable Version Unstable Version License Total Downloads Monthly Downloads Daily Downloads

This extension enhances or adds functionality to existing Yii Framework 2 Widgets to make available other bundled features available in Bootstrap 3.0, new HTML 5 features and affiliated Bootstrap extras.

NOTE: This extension has been revamped with release v3.4.1 on 05-Dec-2015. With release v3.4.0, each widget within this extension bundle has been logically regrouped and split into separate sub repositories. This change has been done to allow developers flexibility to install separately or specific widgets only (via composer) if needed. However, for new users installing this bundle should be the easiest way to give you access to all these important widget sub repositories in one shot. This change would not affect backward compatibility for any users already using the previous extension versions.

Widgets available in this bundle

The yii2-widgets bundle automatically includes extensions or widgets from these sub repositories for accessing via \kartik\widgets\ namespace.

Additional related widgets

This extension has now matured to contain the most needed basic widgets for Yii 2 input and navigation controls. In order to support this extension better, any additional input and navigation widgets will be created separately. Listed below are the additional widgets that are related to similar functionality like the yii2-widgets, but have been created as separate extensions (these widgets depend on kartik-v/yii2-widgets).

  • yii2-dropdown-x: Extended Bootstrap 3 dropdown menu for Yii 2.0
  • yii2-nav-x: Extended Bootstrap 3 navigation menu for Yii 2.0
  • yii2-context-menu: Bootstrap 3 context menu for Yii 2.0
  • yii2-slider: Bootstrap 3 Slider control for Yii 2.0
  • yii2-sortable: Create sortable lists and grids using simple drag and drop.
  • yii2-sortable-input: Input widget for yii2-sortable allowing you to store the sort order.
  • yii2-money: Masked money input widget for Yii 2.0.
  • yii2-checkbox-x: Bootstrap 3 extended checkbox widget with 3 states and more styles for Yii 2.0.
  • yii2-date-range: An extended bootstrap 3 date range picker widget for Yii 2.0.
  • yii2-editable: Convert any displayed content to editable using inputs, widgets, and more features for Yii 2.0.
  • yii2-label-inplace: A form enhancement widget for Yii framework 2.0 allowing in-field label support.

Installation

The preferred way to install this extension is through composer. Remember to refer to the composer.json for this extension's requirements and dependencies.

Pre-requisites

Note: Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

Install

Either run

$ php composer.phar require kartik-v/yii2-widgets "*"

or add

"kartik-v/yii2-widgets": "*"

to the require section of your composer.json file.

Release Updates

Refer the CHANGE LOG for details on changes to various releases.

The widgets currently available in yii2-widgets are grouped by the type of usage.

Forms/Inputs

ActiveForm

VIEW DEMO

Extends Yii ActiveForm widget. Facilitates all three form layouts available in Bootstrap i.e. vertical, horizontal, and inline. Allows options for offsetting labels and inputs for horizontal form layout. Works closely with the extended ActiveField widget.

ActiveField

VIEW DEMO

Extends Yii ActiveField widget. Allows Bootstrap styled input group addons to be prepended or appended to textInputs. Automatically adjusts checkboxes and radio input offsets for horizontal forms. Allows, flexibility to control the labels and placeholders based on form layout style (e.g. hide labels and show them as placeholder for inline forms). The extended ActiveField functionalities available are:

  • Addons
    • Prepend Addon
    • Append Addon
    • Icon Addon
    • Input Addon
    • Button Addon
    • Button Dropdown Addon
    • Segmented Button Addon
    • Prepend & Append
    • Input Group Settings
  • Inputs
    • Checkbox
    • Radio
    • Checkbox List
    • Radio List
    • Static Input
    • HTML 5 Input
  • Multi Select
    • Vertical Form
    • Horizontal Form
    • Radio List
    • Display Options

DepDrop

VIEW DEMO

The DepDrop widget is a Yii 2 wrapper for the dependent-dropdown jQuery plugin by Krajee. This plugin allows multi level dependent dropdown with nested dependencies. The plugin thus enables to convert normal select inputs to a dependent input field, whose options are derived based on value selected in another input/or a group of inputs. It works both with normal select options and select with optgroups as well.

Select2

VIEW DEMO

The Select2 widget is a Yii 2 wrapper for the Select2 jQuery plugin. This input widget is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results. The widget is specially styled for Bootstrap 3. The widget allows graceful degradation to a normal HTML select or text input, if the browser does not support JQuery.

Typeahead

VIEW DEMO

The Typeahead widget is a Yii 2 wrapper for for the Twitter Typeahead.js plugin with certain custom enhancements. This input widget is a jQuery based replacement for text inputs providing search and typeahead functionality. It is inspired by twitter.com's autocomplete search functionality and based on Twitter's typeahead.js which is described as as a fast and fully-featured autocomplete library. The widget is specially styled for Bootstrap 3. The widget allows graceful degradation to a normal HTML text input, if the browser does not support JQuery. You can setup model validation rules for a model attribute that uses Typeahead widget for input like any other field. The widget comes in two variants:

  • TypeaheadBasic: This widget is a basic implementation of the typeahead.js plugin without any suggestion engine. It uses a javascript substring matcher and Regular Expression matching to query and display suggestions. VIEW DEMO

  • Typeahead: This widget is an advanced implementation of the typeahead.js plugin with the BloodHound suggestion engine and the Handlebars template compiler. VIEW DEMO

DatePicker

VIEW DEMO

The DatePicker widget is a Yii 2 wrapper for the Bootstrap DatePicker plugin. The plugin is a fork of Stefan Petre's DatePicker (of eyecon.ro), with improvements by @eternicode. The widget is specially styled for Yii framework 2.0 and Bootstrap 3 and allows graceful degradation to a normal HTML text input, if the browser does not support JQuery. The widget supports these markups:

  • Simple Input Markup
  • Component Markup - Addon Prepended
  • Component Markup - Addon Appended
  • Inline / Embedded Markup
  • Date Range Markup (from and to dates)

TimePicker

VIEW DEMO

The TimePicker widget allows you to easily select a time for a text input using your mouse or keyboards arrow keys. The widget is a wrapper enhancement of the TimePicker plugin by rendom forked from jdewit's TimePicker. This widget as used here has been specially enhanced for Yii framework 2.0 and Bootstrap 3.

DateTimePicker

VIEW DEMO

The DateTimePicker widget is a Yii 2 wrapper for the Bootstrap DateTimePicker plugin. The plugin is a fork of the DateTimePicker plugin by @eternicode and adds the time functionality. The widget is similar to the DatePicker widget in most aspects, except that it adds the time functionality and does not support ranges. The widget is specially styled for Yii framework 2.0 and Bootstrap 3 and allows graceful degradation to a normal HTML text input, if the browser does not support JQuery. The widget supports these markups:

  • Simple Input Markup
  • Component Markup - Addon Prepended
  • Component Markup - Addon Appended
  • Inline / Embedded Markup

TouchSpin

VIEW DEMO

The TouchSpin widget is a Yii 2 wrapper for for the bootstrap-touchspin plugin by István Ujj-Mészáros, with certain additional enhancements. This input widget is a mobile and touch friendly input spinner component for Bootstrap 3. You can use the widget buttons to rapidly increase and decrease numeric and/or decimal values in your input field. The widget can be setup to include model validation rules for the related model attribute.

FileInput

VIEW DEMO

The FileInput widget is a customized file input widget based on Krajee's Bootstrap FileInput JQuery Plugin. The widget enhances the default HTML file input with various features including the following:

  • Specially styled for Bootstrap 3.0 with customizable buttons, caption, and preview
  • Ability to select and preview multiple files
  • Includes file browse and optional remove and upload buttons.
  • Ability to format your file picker button styles
  • Ability to preview files before upload - images and/or text (uses HTML5 FileReader API)
  • Ability to preview multiple files of different types (both images and text)
  • Set your upload action/route (defaults to form submit). Customize the Upload and Remove buttons.
  • Internationalization enabled for easy translation to various languages
Future planned enhancements:
  • Drag and drop functionality
  • Realign/Rearrange the items in preview window
  • Better captioning for each file in the preview window
  • Support for previewing content other than image and text (e.g. HTML)

The widget runs on all modern browsers supporting HTML5 File Inputs and File Processing API. For browser versions IE9 and below, this widget will gracefully degrade to normal HTML file input. The widget is vastly inspired by this blog article and Jasny's File Input plugin.

ColorInput

VIEW DEMO

The ColorInput widget is an advanced ColorPicker input styled for Bootstrap. It uses a combination of the HTML5 color input and/or the JQuery Spectrum Plugin for rendering the color picker. You can use the Native HTML5 color input by setting the useNative option to true. Else, the Spectrum plugin polyfills for unsupported browser versions.

  • Specially styled for Bootstrap 3.0 with customizable caption showing the output of the control.
  • Ability to prepend and append addons.
  • Allow the input to be changed both via the control or the text box.
  • The Spectrum plugin automatically polyfills the HTML5 color input for unsupported browser versions.

RangeInput

VIEW DEMO

The RangeInput widget is a customized range slider control widget based on HTML5 range input. The widget enhances the default HTML range input with various features including the following:

  • Specially styled for Bootstrap 3.0 with customizable caption showing the output of the control.
  • Ability to prepend and append addons (very useful to show the min and max ranges, and the slider measurement unit).
  • Allow the input to be changed both via the control or the text box.
  • Automatically degrade to normal text input for unsupported Internet Explorer versions.

SwitchInput

VIEW DEMO

The SwitchInput widget turns checkboxes and radio buttons into toggle switches. The plugin is a wrapper for the Bootstrap Switch Plugin and is specially styled for Bootstrap 3.

StarRating

VIEW DEMO

The StarRating widget is a wrapper for the Bootstrap Star Rating Plugin JQuery Plugin designed by Krajee. This plugin is a simple yet powerful JQuery star rating plugin for Bootstrap. Developed with a focus on utlizing pure CSS-3 styling to render the control.

Progress

Spinner

VIEW DEMO

The Spinner widget is a wrapper for the spin.js. It enables you to add an animated CSS3 loading spinner which allows VML fallback for IE. Since, its not image based, it allows you to configure the spinner style, size, color, and other CSS attributes. The major advantage of using the CSS3 based spinner, is that the animation can be made visible to user for non-ajax based scenarios. For example on events like window.load or window.unload (thereby enabling you to show a page loading progress without using ajax).

Navigation

Affix

VIEW DEMO

Extends Yii Menu widget. This widget offers a scrollspy and affixed enhanced navigation (upto 2-levels) to highlight sections and secondary sections in each page. The affix widget can be used to generate both the:

  • Sidebar Menu: Displays the scrollspy/affix navigation menu as a sidebar, and/or
  • Main Body: Displays the main body sections based on the section & subsection headings and content passed.

The parameters to pass are:

  • type The affix content type. Must be either menu or body. Defaults to menu
  • items: The affix content items as an array. Check the affix combined usage for a detailed example.

Note: If you have the header section fixed to the top, you must add a CSS class kv-header to the header container. Similarly, for a fixed footer you must add the class kv-footer to your footer container. This will ensure a correct positioning of the affix widget on the page.

SideNav

VIEW DEMO

This widget is a collapsible side navigation menu built to seamlessly work with Bootstrap framework. It is built over Bootstrap stacked nav component. This widget class extends the Yii Menu widget. Upto 3 levels of submenus are by default supported by the CSS styles to balance performance and useability. You can choose to extend it to more or less levels by customizing the CSS.

Notification

Alert

VIEW DEMO

Extends the \yii\bootstrap\Alert widget with more easy styling and auto fade out options.

Growl

VIEW DEMO

A widget that turns standard Bootstrap alerts into "Growl-like" notifications. This widget is a wrapper for the Bootstrap Growl plugin by remabledesigns.

AlertBlock

VIEW DEMO

Alert block widget that groups multiple \kartik\widget\Alert or kartik\widget\Growl widgets in one single block and renders them stacked vertically on the current page. You can choose the TYPE_ALERT style or the TYPE_GROWL style for your notifications. You can also set the widget to automatically read and display session flash messages (which is the default setting). Alternatively, you can setup and configure your own block of custom alerts.

Demo

You can see a demonstration here on usage of these widgets with documentation and examples.

Usage

How to call?

	// add this in your view
	use kartik\widgets\ActiveForm;
	$form = ActiveForm::begin();

ActiveForm

	// Vertical Form
	$form = ActiveForm::begin([
		'id' => 'form-signup',
		'type' => ActiveForm::TYPE_VERTICAL
	]);
  
	// Inline Form
	$form = ActiveForm::begin([
		'id' => 'form-login', 
		'type' => ActiveForm::TYPE_INLINE,
		'fieldConfig' => ['autoPlaceholder'=>true]
	]);

  	// Horizontal Form Configuration
  	$form = ActiveForm::begin([
  		'id' => 'form-signup', 
  		'type' => ActiveForm::TYPE_HORIZONTAL,
		'formConfig' => ['labelSpan' => 3, 'deviceSize' => ActiveForm::SIZE_SMALL]
	]);

ActiveField

	// Prepend an addon text
   	echo $form->field($model, 'email', ['addon' => ['prepend' => ['content'=>'@']]]);
   	
   	// Append an addon text
	echo $form->field($model, 'amount_paid', [
  		'addon' => ['append' => ['content'=>'.00']]
	]);
	
	// Formatted addons (like icons)
	echo $form->field($model, 'phone', [
		'addon' => [
			'prepend' => [
				'content' => '<i class="glyphicon glyphicon-phone"></i>'
			]
		]
	]);
	
	// Formatted addons (inputs)
	echo $form->field($model, 'phone', [
		'addon' => [
			'prepend' => [
				'content' => '<input type="radio">'
			]
		]
	]);
	
	// Formatted addons (buttons)
	echo $form->field($model, 'phone', [
		'addon' => [
			'prepend' => [
				'content' => Html::button('Go', ['class'=>'btn btn-primary'])
			]
			'asButton' => true
		]
	]);

DepDrop

	// Normal parent select
	echo $form->field($model, 'cat')->dropDownList($catList, ['id'=>'cat-id']);

	// Dependent Dropdown
    echo $form->field($model, 'subcat')->widget(DepDrop::classname(), [
         'options' => ['id'=>'subcat-id'],
         'pluginOptions'=>[
             'depends'=>['cat-id'],
             'placeholder' => 'Select...',
             'url' => Url::to(['/site/subcat'])
         ]
     ]);

Select2

	// Normal select with ActiveForm & model
	echo $form->field($model, 'state_1')->widget(Select2::classname(), [
		'data' => array_merge(["" => ""], $data),
		'language' => 'de',
		'options' => ['placeholder' => 'Select a state ...'],
		'pluginOptions' => [
			'allowClear' => true
		],
	]);

	// Multiple select without model
	echo Select2::widget([
		'name' => 'state_2',
		'value' => '',
		'data' => $data,
		'options' => ['multiple' => true, 'placeholder' => 'Select states ...']
	]);

Typeahead

use kartik\widgets\TypeaheadBasic;

// TypeaheadBasic usage with ActiveForm and model
echo $form->field($model, 'state_3')->widget(Typeahead::classname(), [
	'data' => $data,
    'pluginOptions' => ['highlight' => true],
	'options' => ['placeholder' => 'Filter as you type ...'],
]);

// Typeahead usage with ActiveForm and model
echo $form->field($model, 'state_4')->widget(Typeahead::classname(), [
	'dataset' => [
		[
			'local' => $data,
			'limit' => 10
		]
	],
    'pluginOptions' => ['highlight' => true],
	'options' => ['placeholder' => 'Filter as you type ...'],
]);

DatePicker

use kartik\widgets\DatePicker;

// usage without model
echo '<label>Check Issue Date</label>';
echo DatePicker::widget([
	'name' => 'check_issue_date', 
	'value' => date('d-M-Y', strtotime('+2 days')),
	'options' => ['placeholder' => 'Select issue date ...'],
	'pluginOptions' => [
		'format' => 'dd-M-yyyy',
		'todayHighlight' => true
	]
]);

TimePicker

use kartik\widgets\TimePicker;

// usage without model
echo '<label>Start Time</label>';
echo TimePicker::widget([
	'name' => 'start_time', 
	'value' => '11:24 AM',
	'pluginOptions' => [
		'showSeconds' => true
	]
]);

DateTimePicker

use kartik\widgets\DateTimePicker;

// usage without model
echo '<label>Start Date/Time</label>';
echo DateTimePicker::widget([
    'name' => 'datetime_10',
    'options' => ['placeholder' => 'Select operating time ...'],
    'convertFormat' => true,
    'pluginOptions' => [
        'format' => 'd-M-Y g:i A',
        'startDate' => '01-Mar-2014 12:00 AM',
        'todayHighlight' => true
    ]
]);

TouchSpin

use kartik\widgets\TouchSpin;

echo TouchSpin::widget([
    'name' => 'volume',
    'options' => ['placeholder' => 'Adjust...'],
    'pluginOptions' => ['step' => 1]
]);

FileInput

use kartik\widgets\FileInput;

// Usage with ActiveForm and model
echo $form->field($model, 'avatar')->widget(FileInput::classname(), [
    'options' => ['accept' => 'image/*'],
]);

// With model & without ActiveForm
echo '<label class="control-label">Add Attachments</label>';
echo FileInput::widget([
    'model' => $model,
    'attribute' => 'attachment_1',
    'options' => ['multiple' => true]
]);

ColorInput

use kartik\widgets\ColorInput;

// Usage with ActiveForm and model
echo $form->field($model, 'color')->widget(ColorInput::classname(), [
    'options' => ['placeholder' => 'Select color ...'],
]);

// With model & without ActiveForm
echo '<label class="control-label">Select Color</label>';
echo ColorInput::widget([
    'model' => $model,
    'attribute' => 'saturation',
]);

RangeInput

use kartik\widgets\RangeInput;

// Usage with ActiveForm and model
echo $form->field($model, 'rating')->widget(RangeInput::classname(), [
    'options' => ['placeholder' => 'Select color ...'],
    'html5Options' => ['min'=>0, 'max'=>1, 'step'=>1],
    'addon' => ['append'=>['content'=>'star']]
]);

// With model & without ActiveForm
echo '<label class="control-label">Adjust Contrast</label>';
echo RangeInput::widget([
    'model' => $model,
    'attribute' => 'contrast',
    'addon' => ['append'=>['content'=>'%']]
]);

SwitchInput

use kartik\widgets\SwitchInput;

// Usage with ActiveForm and model
echo $form->field($model, 'status')->widget(SwitchInput::classname(), [
    'type' => SwitchInput::CHECKBOX
]);


// With model & without ActiveForm
echo SwitchInput::widget([
    'name' => 'status_1',
    'type' => SwitchInput::RADIO
]);

StarRating

use kartik\widgets\StarRating;

// Usage with ActiveForm and model
echo $form->field($model, 'rating')->widget(StarRating::classname(), [
    'pluginOptions' => ['size'=>'lg']
]);


// With model & without ActiveForm
echo StarRating::widget([
    'name' => 'rating_1',
    'pluginOptions' => ['disabled'=>true, 'showClear'=>false]
]);

Spinner

use kartik\widgets\Spinner;
<div class="well">
<?= Spinner::widget([
    'preset' => Spinner::LARGE,
    'color' => 'blue',
    'align' => 'left'
])?>
</div>

Affix

$content = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.';
$items = [[
	'url' => '#sec-1',
	'label' => 'Section 1',
	'icon' => 'play-circle',
	'content' => $content,
	'items' => [
		['url' => '#sec-1-1', 'label' => 'Section 1.1', 'content' => $content],
		['url' => '#sec-1-2', 'label' => 'Section 1.2', 'content' => $content],
		['url' => '#sec-1-3', 'label' => 'Section 1.3', 'content' => $content],
		['url' => '#sec-1-4', 'label' => 'Section 1.4', 'content' => $content],
		['url' => '#sec-1-5', 'label' => 'Section 1.5', 'content' => $content],
	],
]];

// Displays sidebar menu
echo Affix::widget([
	'items' => $items, 
	'type' => 'menu'
]);

// Displays body sections
echo Affix::widget([
	'items' => $items, 
	'type' => 'body'
]);

SideNav

use kartik\widgets\SideNav;
     
echo SideNav::widget([
	'type' => SideNav::TYPE_DEFAULT,
	'heading' => 'Options',
	'items' => [
		[
			'url' => '#',
			'label' => 'Home',
			'icon' => 'home'
		],
		[
			'label' => 'Help',
			'icon' => 'question-sign',
			'items' => [
				['label' => 'About', 'icon'=>'info-sign', 'url'=>'#'],
				['label' => 'Contact', 'icon'=>'phone', 'url'=>'#'],
			],
		],
	],
]);

Alert

use kartik\widgets\Alert;

echo Alert::widget([
	'type' => Alert::TYPE_INFO,
	'title' => 'Note',
	'titleOptions' => ['icon' => 'info-sign'],
	'body' => 'This is an informative alert'
]);

Growl

use kartik\widgets\Growl;

echo Growl::widget([
	'type' => Growl::TYPE_SUCCESS,
	'icon' => 'glyphicon glyphicon-ok-sign',
	'title' => 'Note',
	'showSeparator' => true,
	'body' => 'This is a successful growling alert.'
]);

AlertBlock

use kartik\widgets\AlertBlock;

echo AlertBlock::widget([
	'type' => AlertBlock::TYPE_ALERT,
	'useSessionFlash' => true
]);

Contributors

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

License

yii2-widgets is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

yii2-widgets's People

Contributors

baibaratsky avatar dmitry-semenov avatar drenty avatar fg avatar kartik-v avatar lars-t avatar maxlapko avatar mbman avatar monkeywithacupcake avatar reksc avatar theill11 avatar thiagotalma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yii2-widgets's Issues

TouchSpin redirect bug

If TouchSpin widget placed into form, it submit form after increasing\descreasing value

TimePicker - PHP Compile Error

TimePicker widget does not work due to a PHP Compile error message

PHP Compile Error – yii\base\ErrorException

Cannot use yii\web\AssetBundle as AssetBundle because the name is already in use

at line 12 in TimePickerAsset.php file: use yii\web\AssetBundle;

It works fine if this line is removed.

This bug also happens on your example.

ActiveField type 'email' has no placeholder

Form declaration:

$form = ActiveForm::begin([
    'type' => ActiveForm::TYPE_INLINE,
    'fieldConfig' => ['autoPlaceholder' => true],
])

field row:

$form->field($model, 'email', ['template' => "{input}"])->input('email')

result:

<div class="form-group field-user-email required">
    <input type="email" id="user-email" class="form-control" name="User[email]">
</div>

input attribute placeholder is empty

Select2

Select2 accept new values ? Values that don't exist in the array passed ?

help

issue
Hey, my datepicker look's like this. I wanna use him for pick a birthdate, and most look like that append in NIB. What should i do ?

property id in array

line 105 in select2 widget = $this->data = array_merge(["" => ""], $this->data);

This line make a array loose is id property.

array( '100' => 'account1', '101' => 'account2');

no debug toolbar

after adding: "kartik-v/yii2-widgets": "dev-master" to my composer.json and run composer update dev my debug toolbar is hiden ant the bottom and shows only:
Not Found (#404): Unable to find debug data tagged with '5361103a76a14'.

any idea why?

Feature Request new Date Widget

The database and internal rules like validators uses format "yyyy-MM-dd HH:mm:ss" always (eg. 2014-11-18 19:10:23). Almost nobody wants to have this on his gui.

That's why there is some wiki and forum entries which propose to format it in model->afterFind ==> present in view ==> unformat it in model->setAttribues or model->beforeValidate.

My opinion is different. With these proposals client validation (via javascript) isn't possible anymore. I think it's a task for the view/client layer only. Yii controller/model knows always the machine readable format and has nothing to do with formatting.

Your DatePicker and this of Yii2 knows the pluginOptions=>['format' => 'dd-m-yyyy']. DatePicker itself uses then this format. Not solved is the communication from and to Yii model.

A good DateWidget should read the model formatted date -> convert to displayed -> show -> after submit the model gets database readable date format. Also on level client a technical formatted date input field must be there because client validation should work.

This is my idea:

The original JQuery UI Datepicker knows an "altField" and "altFormat" (eg. yyyy-m-dd) which is different to showed format. Datepicker converts from field to altField. The assigned AltField must be a hidden input control. see http://api.jqueryui.com/datepicker/

While rendering I would generate two input fields a) #attributeName_disp (visible) and b) #attributeName (hidden).

attributeName_disp is assigned to "name" of datePicker.

altributeName is assigned to "altField" of datePicker

The plug in option "format" is pulled from yii::$app->getFormatter->dateFormat. The formatter class knows the applications language and regional settings.
"altFieldFormat" is fix "yyyy-mm-dd"
The inital input data from model to #attributeName_disp must be converted by getFormatter->format($model-&gt;'attributeName'). I don't know if datePicker must initalized with $('.datePicker').datePicker.setDate(date)?

With this prepartion client side validation of Yii2 should work because validator checks input value of #attributeName and not this of the display version.

Same after submit. The controller sends all input values to $model->load which assigns known input name to attribute array only. #attributeName is known / #attributeName_disp isn't known what will be ignored.

Same process could work with a date widget without binded datePicker. Suche a "date" widget could have an option "datePicker"= true or false

SwitchInput needs new Html::radio parameters?

I really like your widgets. I was working with the radio button version of SwitchInput and was not getting the right values on the input fields. Perhaps the Yii2 Html::radio function has changed since you wrote it. I changed line 120 as follows to get the right values on the inputs:

From: $input = Html::radio($this->name, $value, $options);
To: $input = Html::radio($this->name, false, ["value" => $value]);

Hope this helps.

select2::pass over json data (ajax)

Hi,

populating data seemst to be fine with "normal" datasets, but I have datasets of like 80000 records and I want to filter them by min. 3 entered letters of the user. And after this, data should be loaded dynamically by ajax...
You have a set of usefull samples on the webpage, maybe can you pls add a short sample on how json should be passed over?

Thanks a lot!

The Switch is appearing twice

The Switch widget is being included twice for each field.

From what I could analyze what is causing this error is the selector you're using to generate the Switch, taking the name of the field instead of the id.

In Yii2 for each checkbox field, two fields are generated with the same name, one of them a hidden field to store the value of the checkbox unchecked.

Default checked switchinput

Hello,

Since commit c2a7a43, I can't render a switch input (without model) defaulted to "On".
Before, I was using the "value" property to set it, now, the hidden checkbox has always checked property to false.
I cannot use a $options['checked'] neither, since Html::input is always overriding it with the checked parameter

How can I do ?

Select2 data property does a wrong array merge

When placeholder attribute is given to select2, but no prompt attribute is given, widget adds empty string automatically. But usage of array_merge() function breaks numeric indexes of the $data array.

Initial $data array:

array (size=6)
  1 => string 'Single Male' (length=11)
  2 => string 'Single Female' (length=13)
  3 => string 'TV/CD' (length=5)
  4 => string 'Couple' (length=6)
  5 => string 'Transex' (length=7)
  6 => string 'Gangbang Group' (length=14)

Finished $data array:

array (size=7)
  '' => string '' (length=0)
  0 => string 'Single Male' (length=11)
  1 => string 'Single Female' (length=13)
  2 => string 'TV/CD' (length=5)
  3 => string 'Couple' (length=6)
  4 => string 'Transex' (length=7)
  5 => string 'Gangbang Group' (length=14)

It can be fixed by using ArrayHelper::merge() method instead of array_merge().

Implement DateTime Picker

Hi Kartik-v,

I found the extension so awesome.
But for the date & time picker to standalone, whenerver I need to add a Date time field, I have to parse and group 2 input element. That is not so convenient.

But install another extension is expensive.

Can you try to merge the datetime picker plugins into the extension?

http://www.malot.fr/bootstrap-datetimepicker/demo.php

That would be awesome!

Select2 - Indication that the field will change (loading)

When I use the Select2 and the request to retrieve the initial data is slow, missing an indication that the field is updated.

One suggestion is to create a CSS class to display the spinner as the background of the original field.

Anything like this:

    protected function renderInput() {
        Html::addCssClass($this->options, 'select2-loading');
        (...)
    }

Congratulations for the excellent work.
Hugs!

What happen ? Can you do a stable realise ?

Men, I have your plugin in one client and yesterday that happens:

captura de ecra 2014-02-15 as 11 06 23
Can you solve this ? Maybe you want do that in a stable release and start all the changes in a branch ?

Brainstorming: inline form and error block (again)

I think error block isn't useful in inline form. It creates a space in the bottom of each field.
I suggest to put a param to avoid the help-block div or let modify the field template using a formField property.
You fixed button alignment by margin-top: -10px;
I think it could be a better solution...

image2

Save the options of the plugins in a variable.

Hello Kartik,

Today I made a change to a widget that I have and I believe it would be very good in their widgets, especially when using TabularForm, cloning fields with some attached plugin.

I create a global variable with the configuration object and keep the name of the variable in the input data. This way is much simpler when I need to clone an input and apply the settings of a jQuery plugin like Select2 or Switch.

Moreover, in this way we avoid repeating the same configuration multiple times when there are many fields with the same configuration.

Take a look: thiagotalma/yii2-inputmask-widget@e2c5b63

If you have any criticism or comment, feel free.

Validation-errors for DatePicker::TYPE_RANGE

When using the DatePicker as TYPE_RANGE, the validation-errors for the second field is not shown.

E.g. if I define both start_date and end_date as required in my model, only errors for start_date is shown.

Configuration in php for FileInput Widget

I want to upload a gravater of the user.

// Multiple file/image selection with image only preview
        echo $form->field($modelimage, 'image_name')->widget(FileInput::classname(), [
            'options' => ['multiple' => true, 'accept' => 'image/*'],
            'pluginOptions' => ['previewFileType' => 'image']
        ]);
        ?>

I want to know the code which should be written.

wrong composer psr-4 definition - sorry missing yii widget class in use!

Hi, by the way u use the psr-4 definition, the namespace you are using throws an error:

Class 'kartik\widgets\Widget' not found

1. in /Users/philippfrenzel/Sites/pliq/purepo/vendor/kartik-v/yii2-widgets/widgets/Select2.php at line 29
2425262728293031323334  

 *
 * @author Kartik Visweswaran <[email protected]>
 * @since 1.0
 * @see http://ivaynberg.github.com/select2/
 */
class Select2 extends Widget {

    const LARGE = 'lg';
    const MEDIUM = 'md';
    const SMALL = 'sm';


2. yii\base\Application::handleFatalError() 

Setting unknown property

I updated the last version of widgets and I am getting this error:

Setting unknown property: kartik\widgets\FileInput::showUpload
Setting unknown property: kartik\widgets\FileInput::buttonOptions
Setting unknown property: kartik\widgets\FileInput::removeOptions
Setting unknown property: kartik\widgets\FileInput::groupOptions

My code is:

 <?= $form->field($physicalInvoice, 'attachment_url')->widget(
        FileInput::classname(), [
            'options' => ['accept' => 'image/*'],
            'showUpload' => false,
            'buttonOptions' => ['label' => false],
            'removeOptions' => ['label' => false],
            'groupOptions' => ['class' => 'input-group-lg']
        ]
);?>

If I remove showUpload, buttonOptions, removeOptions, groupOptions it works.

Select2 data property does not work as expected.

echo $form->field($model, 'created_user')->widget(Select2::classname(), [
    'language' => 'ru',
    'size' => 'sm',
    'data' => array_merge(["" => ""], common\models\Ticket::getCreatedUsersList()),
    'options' => ['placeholder' => 'Выберите автора заявки ...'],
    'pluginOptions' => [
        'allowClear' => true
    ],
]);

static public function getCreatedUsersList()
{
$users = User::find()->where(['role' => User::ROLE_USER])->all();

    $usersArray = array();
    foreach ($users as $key => $user)
        $usersArray["$user->id"] = $user->showName();

    return $usersArray;
}

getCreatedUsersList is Ticket model's method.
The result select is:
.....
Тестов Тест

As you see, option's value is not id of user.

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.