1: <?php
2: /**
3: * TbActiveForm class file.
4: * @author Antonio Ramirez <[email protected]>
5: * @copyright Copyright © Christoffer Niska 2013-
6: * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
7: * @package bootstrap.widgets
8: */
9:
10: Yii::import('bootstrap.helpers.TbHtml');
11: Yii::import('bootstrap.behaviors.TbWidget');
12:
13: /**
14: * Bootstrap active form widget.
15: */
16: class TbActiveForm extends CActiveForm
17: {
18: /**
19: * @var string the form layout.
20: */
21: public $layout;
22: /**
23: * @var string the help type. Valid values are TbHtml::HELP_INLINE and TbHtml::HELP_BLOCK.
24: */
25: public $helpType = TbHtml::HELP_TYPE_BLOCK;
26: /**
27: * @var string the CSS class name for error messages.
28: */
29: public $errorMessageCssClass = 'error';
30: /**
31: * @var string the CSS class name for success messages.
32: */
33: public $successMessageCssClass = 'success';
34:
35: /**
36: * @var boolean whether to hide inline errors. Defaults to false.
37: */
38: public $hideInlineErrors = false;
39:
40: /**
41: * Initializes the widget.
42: */
43: public function init()
44: {
45: $this->attachBehavior('TbWidget', new TbWidget);
46: $this->copyId();
47: if ($this->stateful) {
48: echo TbHtml::statefulFormTb($this->layout, $this->action, $this->method, $this->htmlOptions);
49: } else {
50: echo TbHtml::beginFormTb($this->layout, $this->action, $this->method, $this->htmlOptions);
51: }
52: }
53:
54: /**
55: * Displays the first validation error for a model attribute.
56: * @param CModel $model the data model
57: * @param string $attribute the attribute name
58: * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
59: * @param boolean $enableAjaxValidation whether to enable AJAX validation for the specified attribute.
60: * @param boolean $enableClientValidation whether to enable client-side validation for the specified attribute.
61: * @return string the validation result (error display or success message).
62: */
63: public function error(
64: $model,
65: $attribute,
66: $htmlOptions = array(),
67: $enableAjaxValidation = true,
68: $enableClientValidation = true
69: ) {
70: if (!$this->enableAjaxValidation) {
71: $enableAjaxValidation = false;
72: }
73: if (!$this->enableClientValidation) {
74: $enableClientValidation = false;
75: }
76: if (!$enableAjaxValidation && !$enableClientValidation) {
77: return TbHtml::error($model, $attribute, $htmlOptions);
78: }
79: $id = CHtml::activeId($model, $attribute);
80: $inputID = TbArray::getValue('inputID', $htmlOptions, $id);
81: unset($htmlOptions['inputID']);
82: TbArray::defaultValue('id', $inputID . '_em_', $htmlOptions);
83: $option = array(
84: 'id' => $id,
85: 'inputID' => $inputID,
86: 'errorID' => $htmlOptions['id'],
87: 'model' => get_class($model),
88: 'name' => $attribute,
89: 'enableAjaxValidation' => $enableAjaxValidation,
90: 'inputContainer' => 'div.control-group', // Bootstrap requires this
91: );
92: $optionNames = array(
93: 'validationDelay',
94: 'validateOnChange',
95: 'validateOnType',
96: 'hideErrorMessage',
97: 'inputContainer',
98: 'errorCssClass',
99: 'successCssClass',
100: 'validatingCssClass',
101: 'beforeValidateAttribute',
102: 'afterValidateAttribute',
103: );
104: foreach ($optionNames as $name) {
105: if (isset($htmlOptions[$name])) {
106: $option[$name] = TbArray::popValue($name, $htmlOptions);
107: }
108: }
109: if ($model instanceof CActiveRecord && !$model->isNewRecord) {
110: $option['status'] = 1;
111: }
112: if ($enableClientValidation) {
113: $validators = TbArray::getValue('clientValidation', $htmlOptions, array());
114: $attributeName = $attribute;
115: if (($pos = strrpos($attribute, ']')) !== false && $pos !== strlen($attribute) - 1) // e.g. [a]name
116: {
117: $attributeName = substr($attribute, $pos + 1);
118: }
119: foreach ($model->getValidators($attributeName) as $validator) {
120: if ($validator->enableClientValidation) {
121: if (($js = $validator->clientValidateAttribute($model, $attributeName)) != '') {
122: $validators[] = $js;
123: }
124: }
125: }
126: if ($validators !== array()) {
127: $option['clientValidation'] = "js:function(value, messages, attribute) {\n" . implode(
128: "\n",
129: $validators
130: ) . "\n}";
131: }
132: }
133: $html = TbHtml::error($model, $attribute, $htmlOptions);
134: if ($html === '') {
135: $htmlOptions['type'] = $this->helpType;
136: TbHtml::addCssStyle('display:none', $htmlOptions);
137: $html = TbHtml::help('', $htmlOptions);
138: }
139: $this->attributes[$inputID] = $option;
140: return $html;
141: }
142:
143: /**
144: * Displays a summary of validation errors for one or several models.
145: * @param mixed $models the models whose input errors are to be displayed.
146: * @param string $header a piece of HTML code that appears in front of the errors
147: * @param string $footer a piece of HTML code that appears at the end of the errors
148: * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag.
149: * @return string the error summary. Empty if no errors are found.
150: */
151: public function errorSummary($models, $header = null, $footer = null, $htmlOptions = array())
152: {
153: if (!$this->enableAjaxValidation && !$this->enableClientValidation) {
154: return TbHtml::errorSummary($models, $header, $footer, $htmlOptions);
155: }
156: TbArray::defaultValue('id', $this->id . '_es_', $htmlOptions);
157: $html = TbHtml::errorSummary($models, $header, $footer, $htmlOptions);
158: if ($html === '') {
159: if ($header === null) {
160: $header = '<p>' . Yii::t('yii', 'Please fix the following input errors:') . '</p>';
161: }
162: TbHtml::addCssClass(TbHtml::$errorSummaryCss, $htmlOptions);
163: TbHtml::addCssStyle('display:none', $htmlOptions);
164: $html = CHtml::tag('div', $htmlOptions, $header . '<ul><li>dummy</li></ul>' . $footer);
165: }
166: $this->summaryID = $htmlOptions['id'];
167: return $html;
168: }
169:
170: /**
171: * Generates a text field for a model attribute.
172: * @param CModel $model the data model.
173: * @param string $attribute the attribute.
174: * @param array $htmlOptions additional HTML attributes.
175: * @return string the generated input field.
176: * @see TbHtml::activeTextField
177: */
178: public function textField($model, $attribute, $htmlOptions = array())
179: {
180: return $this->createInput(TbHtml::INPUT_TYPE_TEXT, $model, $attribute, $htmlOptions);
181: }
182:
183: /**
184: * Generates a password field for a model attribute.
185: * @param CModel $model the data model.
186: * @param string $attribute the attribute.
187: * @param array $htmlOptions additional HTML attributes.
188: * @return string the generated input field.
189: * @see TbHtml::activePasswordField
190: */
191: public function passwordField($model, $attribute, $htmlOptions = array())
192: {
193: return $this->createInput(TbHtml::INPUT_TYPE_PASSWORD, $model, $attribute, $htmlOptions);
194: }
195:
196: /**
197: * Generates an url field for a model attribute.
198: * @param CModel $model the data model
199: * @param string $attribute the attribute
200: * @param array $htmlOptions additional HTML attributes.
201: * @return string the generated input field
202: * @see TbHtml::activeUrlField
203: */
204: public function urlField($model, $attribute, $htmlOptions = array())
205: {
206: return $this->createInput(TbHtml::INPUT_TYPE_URL, $model, $attribute, $htmlOptions);
207: }
208:
209: /**
210: * Generates an email field for a model attribute.
211: * @param CModel $model the data model.
212: * @param string $attribute the attribute.
213: * @param array $htmlOptions additional HTML attributes.
214: * @return string the generated input field.
215: * @see TbHtml::activeEmailField
216: */
217: public function emailField($model, $attribute, $htmlOptions = array())
218: {
219: return $this->createInput(TbHtml::INPUT_TYPE_EMAIL, $model, $attribute, $htmlOptions);
220: }
221:
222: /**
223: * Generates a number field for a model attribute.
224: * @param CModel $model the data model.
225: * @param string $attribute the attribute.
226: * @param array $htmlOptions additional HTML attributes.
227: * @return string the generated input field.
228: * @see TbHtml::activeNumberField
229: */
230: public function numberField($model, $attribute, $htmlOptions = array())
231: {
232: return $this->createInput(TbHtml::INPUT_TYPE_NUMBER, $model, $attribute, $htmlOptions);
233: }
234:
235: /**
236: * Generates a range field for a model attribute.
237: * @param CModel $model the data model.
238: * @param string $attribute the attribute.
239: * @param array $htmlOptions additional HTML attributes.
240: * @return string the generated input field.
241: * @see TbHtml::activeRangeField
242: */
243: public function rangeField($model, $attribute, $htmlOptions = array())
244: {
245: return $this->createInput(TbHtml::INPUT_TYPE_RANGE, $model, $attribute, $htmlOptions);
246: }
247:
248: /**
249: * Generates a date field for a model attribute.
250: * @param CModel $model the data model.
251: * @param string $attribute the attribute.
252: * @param array $htmlOptions additional HTML attributes.
253: * @return string the generated input field.
254: */
255: public function dateField($model, $attribute, $htmlOptions = array())
256: {
257: return $this->createInput(TbHtml::INPUT_TYPE_DATE, $model, $attribute, $htmlOptions);
258: }
259:
260: /**
261: * Generates a text area for a model attribute.
262: * @param CModel $model the data model.
263: * @param string $attribute the attribute.
264: * @param array $htmlOptions additional HTML attributes.
265: * @return string the generated text area.
266: * @see TbHtml::activeTextArea
267: */
268: public function textArea($model, $attribute, $htmlOptions = array())
269: {
270: return $this->createInput(TbHtml::INPUT_TYPE_TEXTAREA, $model, $attribute, $htmlOptions);
271: }
272:
273: /**
274: * Generates a file field for a model attribute.
275: * @param CModel $model the data model.
276: * @param string $attribute the attribute.
277: * @param array $htmlOptions additional HTML attributes
278: * @return string the generated input field.
279: * @see TbHtml::activeFileField
280: */
281: public function fileField($model, $attribute, $htmlOptions = array())
282: {
283: return $this->createInput(TbHtml::INPUT_TYPE_FILE, $model, $attribute, $htmlOptions);
284: }
285:
286: /**
287: * Generates a radio button for a model attribute.
288: * @param CModel $model the data model.
289: * @param string $attribute the attribute.
290: * @param array $htmlOptions additional HTML attributes.
291: * @return string the generated radio button.
292: * @see TbHtml::activeRadioButton
293: */
294: public function radioButton($model, $attribute, $htmlOptions = array())
295: {
296: return $this->createInput(TbHtml::INPUT_TYPE_RADIOBUTTON, $model, $attribute, $htmlOptions);
297: }
298:
299: /**
300: * Generates a checkbox for a model attribute.
301: * @param CModel $model the data model.
302: * @param string $attribute the attribute.
303: * @param array $htmlOptions additional HTML attributes.
304: * @return string the generated check box.
305: * @see TbHtml::activeCheckBox
306: */
307: public function checkBox($model, $attribute, $htmlOptions = array())
308: {
309: return $this->createInput(TbHtml::INPUT_TYPE_CHECKBOX, $model, $attribute, $htmlOptions);
310: }
311:
312: /**
313: * Generates a dropdown list for a model attribute.
314: * @param CModel $model the data model.
315: * @param string $attribute the attribute.
316: * @param array $data data for generating the list options (value=>display).
317: * @param array $htmlOptions additional HTML attributes.
318: * @return string the generated drop down list.
319: * @see TbHtml::activeDropDownList
320: */
321: public function dropDownList($model, $attribute, $data, $htmlOptions = array())
322: {
323: return $this->createInput(TbHtml::INPUT_TYPE_DROPDOWNLIST, $model, $attribute, $htmlOptions, $data);
324: }
325:
326: /**
327: * Generates a list box for a model attribute.
328: * @param CModel $model the data model.
329: * @param string $attribute the attribute.
330: * @param array $data data for generating the list options (value=>display).
331: * @param array $htmlOptions additional HTML attributes.
332: * @return string the generated list box.
333: * @see TbHtml::activeListBox
334: */
335: public function listBox($model, $attribute, $data, $htmlOptions = array())
336: {
337: return $this->createInput(TbHtml::INPUT_TYPE_LISTBOX, $model, $attribute, $htmlOptions, $data);
338: }
339:
340: /**
341: * Generates a radio button list for a model attribute
342: * @param CModel $model the data model.
343: * @param string $attribute the attribute.
344: * @param array $data data for generating the list options (value=>display)
345: * @param array $htmlOptions additional HTML attributes.
346: * @return string the generated radio button list.
347: * @see TbHtml::activeRadioButtonList
348: */
349: public function radioButtonList($model, $attribute, $data, $htmlOptions = array())
350: {
351: return $this->createInput(TbHtml::INPUT_TYPE_RADIOBUTTONLIST, $model, $attribute, $htmlOptions, $data);
352: }
353:
354: /**
355: * Generates an inline radio button list for a model attribute
356: * @param CModel $model the data model.
357: * @param string $attribute the attribute.
358: * @param array $data data for generating the list options (value=>display)
359: * @param array $htmlOptions additional HTML attributes.
360: * @return string the generated radio button list.
361: * @see TbHtml::activeInlineRadioButtonList
362: */
363: public function inlineRadioButtonList($model, $attribute, $data, $htmlOptions = array())
364: {
365: $htmlOptions['inline'] = true;
366: return $this->createInput(TbHtml::INPUT_TYPE_RADIOBUTTONLIST, $model, $attribute, $htmlOptions, $data);
367: }
368:
369: /**
370: * Generates a checkbox list for a model attribute.
371: * @param CModel $model the data model.
372: * @param string $attribute the attribute.
373: * @param array $data data for generating the list options (value=>display)
374: * @param array $htmlOptions additional HTML attributes.
375: * @return string the generated checkbox list.
376: * @see TbHtml::activeCheckBoxList
377: */
378: public function checkBoxList($model, $attribute, $data, $htmlOptions = array())
379: {
380: return $this->createInput(TbHtml::INPUT_TYPE_CHECKBOXLIST, $model, $attribute, $htmlOptions, $data);
381: }
382:
383: /**
384: * Generates an inline checkbox list for a model attribute.
385: * @param CModel $model the data model.
386: * @param string $attribute the attribute.
387: * @param array $data data for generating the list options (value=>display)
388: * @param array $htmlOptions additional HTML attributes.
389: * @return string the generated checkbox list.
390: * @see TbHtml::activeInlineCheckBoxList
391: */
392: public function inlineCheckBoxList($model, $attribute, $data, $htmlOptions = array())
393: {
394: $htmlOptions['inline'] = true;
395: return $this->createInput(TbHtml::INPUT_TYPE_CHECKBOXLIST, $model, $attribute, $htmlOptions, $data);
396: }
397:
398: /**
399: * Generates an uneditable field for a model attribute.
400: * @param CModel $model the data model.
401: * @param string $attribute the attribute.
402: * @param array $htmlOptions additional HTML attributes.
403: * @return string the generated field.
404: * @see TbHtml::activeUneditableField
405: */
406: public function uneditableField($model, $attribute, $htmlOptions = array())
407: {
408: return $this->createInput(TbHtml::INPUT_TYPE_UNEDITABLE, $model, $attribute, $htmlOptions);
409: }
410:
411: /**
412: * Generates a search query field for a model attribute.
413: * @param CModel $model the data model.
414: * @param string $attribute the attribute.
415: * @param array $htmlOptions additional HTML attributes.
416: * @return string the generated input.
417: * @see TbHtml::activeSearchField
418: */
419: public function searchQuery($model, $attribute, $htmlOptions = array())
420: {
421: return $this->createInput(TbHtml::INPUT_TYPE_SEARCH, $model, $attribute, $htmlOptions);
422: }
423:
424: /**
425: * Generates an input for a model attribute.
426: * @param string $type the input type.
427: * @param CModel $model the data model.
428: * @param string $attribute the attribute.
429: * @param array $htmlOptions additional HTML attributes.
430: * @param array $data data for generating the list options (value=>display).
431: * @return string the generated input.
432: * @see TbHtml::createActiveInput
433: */
434: public function createInput($type, $model, $attribute, $htmlOptions = array(), $data = array())
435: {
436: return TbHtml::createActiveInput($type, $model, $attribute, $htmlOptions, $data);
437: }
438:
439: /**
440: * Generates a control group with a text field for a model attribute.
441: * @param CModel $model the data model.
442: * @param string $attribute the attribute name.
443: * @param array $htmlOptions additional HTML attributes.
444: * @return string the generated control group.
445: * @see TbHtml::activeTextFieldControlGroup
446: */
447: public function textFieldControlGroup($model, $attribute, $htmlOptions = array())
448: {
449: return $this->createControlGroup(TbHtml::INPUT_TYPE_TEXT, $model, $attribute, $htmlOptions);
450: }
451:
452: /**
453: * Generates a control group with a password field for a model attribute.
454: * @param CModel $model the data model.
455: * @param string $attribute the attribute name.
456: * @param array $htmlOptions additional HTML attributes.
457: * @return string the generated control group.
458: * @see TbHtml::activePasswordFieldControlGroup
459: */
460: public function passwordFieldControlGroup($model, $attribute, $htmlOptions = array())
461: {
462: return $this->createControlGroup(TbHtml::INPUT_TYPE_PASSWORD, $model, $attribute, $htmlOptions);
463: }
464:
465: /**
466: * Generates a control group with an url field for a model attribute.
467: * @param CModel $model the data model.
468: * @param string $attribute the attribute name.
469: * @param array $htmlOptions additional HTML attributes.
470: * @return string the generated control group.
471: * @see TbHtml::activeUrlFieldControlGroup
472: */
473: public function urlFieldControlGroup($model, $attribute, $htmlOptions = array())
474: {
475: return $this->createControlGroup(TbHtml::INPUT_TYPE_URL, $model, $attribute, $htmlOptions);
476: }
477:
478: /**
479: * Generates a control group with an email field for a model attribute.
480: * @param CModel $model the data model.
481: * @param string $attribute the attribute name.
482: * @param array $htmlOptions additional HTML attributes.
483: * @return string the generated control group.
484: * @see TbHtml::activeEmailFieldControlGroup
485: */
486: public function emailFieldControlGroup($model, $attribute, $htmlOptions = array())
487: {
488: return $this->createControlGroup(TbHtml::INPUT_TYPE_EMAIL, $model, $attribute, $htmlOptions);
489: }
490:
491: /**
492: * Generates a control group with a number field for a model attribute.
493: * @param CModel $model the data model.
494: * @param string $attribute the attribute name.
495: * @param array $htmlOptions additional HTML attributes.
496: * @return string the generated control group.
497: * @see TbHtml::activeNumberFieldControlGroup
498: */
499: public function numberFieldControlGroup($model, $attribute, $htmlOptions = array())
500: {
501: return $this->createControlGroup(TbHtml::INPUT_TYPE_NUMBER, $model, $attribute, $htmlOptions);
502: }
503:
504: /**
505: * Generates a control group with a range field for a model attribute.
506: * @param CModel $model the data model.
507: * @param string $attribute the attribute name.
508: * @param array $htmlOptions additional HTML attributes.
509: * @return string the generated control group.
510: * @see TbHtml::activeRangeFieldControlGroup
511: */
512: public function rangeFieldControlGroup($model, $attribute, $htmlOptions = array())
513: {
514: return $this->createControlGroup(TbHtml::INPUT_TYPE_RANGE, $model, $attribute, $htmlOptions);
515: }
516:
517: /**
518: * Generates a control group with a date field for a model attribute.
519: * @param CModel $model the data model.
520: * @param string $attribute the attribute name.
521: * @param array $htmlOptions additional HTML attributes.
522: * @return string the generated control group.
523: * @see TbHtml::activeDateFieldControlGroup
524: */
525: public function dateFieldControlGroup($model, $attribute, $htmlOptions = array())
526: {
527: return $this->createControlGroup(TbHtml::INPUT_TYPE_DATE, $model, $attribute, $htmlOptions);
528: }
529:
530: /**
531: * Generates a control group with a text area for a model attribute.
532: * @param CModel $model the data model.
533: * @param string $attribute the attribute name.
534: * @param array $htmlOptions additional HTML attributes.
535: * @return string the generated control group.
536: * @see TbHtml::activeTextAreaControlGroup
537: */
538: public function textAreaControlGroup($model, $attribute, $htmlOptions = array())
539: {
540: return $this->createControlGroup(TbHtml::INPUT_TYPE_TEXTAREA, $model, $attribute, $htmlOptions);
541: }
542:
543: /**
544: * Generates a control group with a check box for a model attribute.
545: * @param CModel $model the data model.
546: * @param string $attribute the attribute name.
547: * @param array $htmlOptions additional HTML attributes.
548: * @return string the generated control group.
549: * @see TbHtml::activeCheckBoxControlGroup
550: */
551: public function checkBoxControlGroup($model, $attribute, $htmlOptions = array())
552: {
553: return $this->createControlGroup(TbHtml::INPUT_TYPE_CHECKBOX, $model, $attribute, $htmlOptions);
554: }
555:
556: /**
557: * Generates a control group with a radio button for a model attribute.
558: * @param CModel $model the data model.
559: * @param string $attribute the attribute name.
560: * @param array $htmlOptions additional HTML attributes.
561: * @return string the generated control group.
562: * @see TbHtml::activeRadioButtonControlGroup
563: */
564: public function radioButtonControlGroup($model, $attribute, $htmlOptions = array())
565: {
566: return $this->createControlGroup(TbHtml::INPUT_TYPE_RADIOBUTTON, $model, $attribute, $htmlOptions);
567: }
568:
569: /**
570: * Generates a control group with a drop down list for a model attribute.
571: * @param CModel $model the data model.
572: * @param string $attribute the attribute name.
573: * @param array $data data for generating the list options (value=>display).
574: * @param array $htmlOptions additional HTML attributes.
575: * @return string the generated control group.
576: * @see TbHtml::activeDropDownListControlGroup
577: */
578: public function dropDownListControlGroup($model, $attribute, $data, $htmlOptions = array())
579: {
580: return $this->createControlGroup(TbHtml::INPUT_TYPE_DROPDOWNLIST, $model, $attribute, $htmlOptions, $data);
581: }
582:
583: /**
584: * Generates a control group with a list box for a model attribute.
585: * @param CModel $model the data model.
586: * @param string $attribute the attribute name.
587: * @param array $data data for generating the list options (value=>display).
588: * @param array $htmlOptions additional HTML attributes.
589: * @return string the generated control group.
590: * @see TbHtml::activeListBoxControlGroup
591: */
592: public function listBoxControlGroup($model, $attribute, $data, $htmlOptions = array())
593: {
594: return $this->createControlGroup(TbHtml::INPUT_TYPE_LISTBOX, $model, $attribute, $htmlOptions, $data);
595: }
596:
597: /**
598: * Generates a control group with a file field for a model attribute.
599: * @param CModel $model the data model.
600: * @param string $attribute the attribute name.
601: * @param array $htmlOptions additional HTML attributes.
602: * @return string the generated control group.
603: * @see TbHtml::activeFileFieldControlGroup
604: */
605: public function fileFieldControlGroup($model, $attribute, $htmlOptions = array())
606: {
607: return $this->createControlGroup(TbHtml::INPUT_TYPE_FILE, $model, $attribute, $htmlOptions);
608: }
609:
610: /**
611: * Generates a control group with a radio button list for a model attribute.
612: * @param CModel $model the data model.
613: * @param string $attribute the attribute name.
614: * @param array $data data for generating the list options (value=>display).
615: * @param array $htmlOptions additional HTML attributes.
616: * @return string the generated control group.
617: * @see TbHtml::activeRadioButtonListControlGroup
618: */
619: public function radioButtonListControlGroup($model, $attribute, $data, $htmlOptions = array())
620: {
621: return $this->createControlGroup(TbHtml::INPUT_TYPE_RADIOBUTTONLIST, $model, $attribute, $htmlOptions, $data);
622: }
623:
624: /**
625: * Generates a control group with an inline radio button list for a model attribute.
626: * @param CModel $model the data model.
627: * @param string $attribute the attribute name.
628: * @param array $data data for generating the list options (value=>display).
629: * @param array $htmlOptions additional HTML attributes.
630: * @return string the generated control group.
631: * @see TbHtml::activeInlineCheckBoxListControlGroup
632: */
633: public function inlineRadioButtonListControlGroup($model, $attribute, $data, $htmlOptions = array())
634: {
635: $htmlOptions['inline'] = true;
636: return $this->createControlGroup(TbHtml::INPUT_TYPE_RADIOBUTTONLIST, $model, $attribute, $htmlOptions, $data);
637: }
638:
639: /**
640: * Generates a control group with a check box list for a model attribute.
641: * @param CModel $model the data model.
642: * @param string $attribute the attribute name.
643: * @param array $data data for generating the list options (value=>display).
644: * @param array $htmlOptions additional HTML attributes.
645: * @return string the generated control group.
646: * @see TbHtml::activeCheckBoxListControlGroup
647: */
648: public function checkBoxListControlGroup($model, $attribute, $data, $htmlOptions = array())
649: {
650: return $this->createControlGroup(TbHtml::INPUT_TYPE_CHECKBOXLIST, $model, $attribute, $htmlOptions, $data);
651: }
652:
653: /**
654: * Generates a control group with an inline check box list for a model attribute.
655: * @param CModel $model the data model.
656: * @param string $attribute the attribute name.
657: * @param array $data data for generating the list options (value=>display).
658: * @param array $htmlOptions additional HTML attributes.
659: * @return string the generated control group.
660: * @see TbHtml::activeInlineCheckBoxListControlGroup
661: */
662: public function inlineCheckBoxListControlGroup($model, $attribute, $data, $htmlOptions = array())
663: {
664: $htmlOptions['inline'] = true;
665: return $this->createControlGroup(TbHtml::INPUT_TYPE_CHECKBOXLIST, $model, $attribute, $htmlOptions, $data);
666: }
667:
668: /**
669: * Generates a control group with an uneditable field for a model attribute.
670: * @param CModel $model the data model.
671: * @param string $attribute the attribute name.
672: * @param array $htmlOptions additional HTML attributes.
673: * @return string the generated control group.
674: * @see TbHtml::activeUneditableFieldControlGroup
675: */
676: public function uneditableFieldControlGroup($model, $attribute, $htmlOptions = array())
677: {
678: return $this->createControlGroup(TbHtml::INPUT_TYPE_UNEDITABLE, $model, $attribute, $htmlOptions);
679: }
680:
681: /**
682: * Generates a control group with a search field for a model attribute.
683: * @param CModel $model the data model.
684: * @param string $attribute the attribute name.
685: * @param array $htmlOptions additional HTML attributes.
686: * @return string the generated control group.
687: * @see TbHtml::activeSearchFieldControlGroup
688: */
689: public function searchQueryControlGroup($model, $attribute, $htmlOptions = array())
690: {
691: return $this->createControlGroup(TbHtml::INPUT_TYPE_SEARCH, $model, $attribute, $htmlOptions);
692: }
693:
694: /**
695: * Generates a control group for a model attribute.
696: * @param string $type the input type.
697: * @param CModel $model the data model.
698: * @param string $attribute the attribute name.
699: * @param array $htmlOptions additional HTML attributes.
700: * @param array $data data for generating the list options (value=>display).
701: * @return string the generated control group.
702: * @see TbHtml::activeControlGroup
703: */
704: public function createControlGroup($type, $model, $attribute, $htmlOptions = array(), $data = array())
705: {
706: $htmlOptions = $this->processControlGroupOptions($model, $attribute, $htmlOptions);
707: return TbHtml::activeControlGroup($type, $model, $attribute, $htmlOptions, $data);
708: }
709:
710: /**
711: * Processes the options for a input row.
712: * @param CModel $model the data model.
713: * @param string $attribute the attribute name.
714: * @param array $options the options.
715: * @return array the processed options.
716: */
717: protected function processControlGroupOptions($model, $attribute, $options)
718: {
719: $errorOptions = TbArray::popValue('errorOptions', $options, array());
720: $errorOptions['type'] = $this->helpType;
721: $error = $this->error($model, $attribute, $errorOptions);
722: // kind of a hack for ajax forms but this works for now.
723: if (!empty($error) && strpos($error, 'display:none') === false) {
724: $options['color'] = TbHtml::INPUT_COLOR_ERROR;
725: }
726: if (!$this->hideInlineErrors) {
727: $options['error'] = $error;
728: }
729: $helpOptions = TbArray::popValue('helpOptions', $options, array());
730: $helpOptions['type'] = $this->helpType;
731: $options['helpOptions'] = $helpOptions;
732: return $options;
733: }
734: }
735: