public function run() { echo BHtml::closeTag('div'); // body if (!empty($this->actions)) { $actions = array(); foreach ($this->actions as $action) { $tagType = 'link'; if (!is_array($action)) { $action = array('text' => $action); } if (!isset($action['text'])) { $action['text'] = 'Action'; } if (!isset($action['url'])) { $tagType = 'button'; } if (!isset($action['htmlOptions'])) { $action['htmlOptions'] = array('class' => 'btn small'); } else { $action['htmlOptions']['class'] = (isset($action['htmlOptions']['class']) ? $action['htmlOptions']['class'] . ' ' : '') . 'btn small'; } if (isset($action['primary']) && $action['primary']) { $action['htmlOptions']['class'] .= ' primary'; } if (isset($action['onclick'])) { $action['htmlOptions']['onclick'] = (isset($action['htmlOptions']['onclick']) ? $action['htmlOptions']['onclick'] : '') . $action['onclick']; } if (isset($action['close']) && $action['close']) { $action['htmlOptions']['onclick'] = (isset($action['onclick']) ? $action['onclick'] : '') . ';$("#' . $this->id . '").modal("hide");'; } $actions[] = $tagType == 'link' ? CHtml::link($action['text'], $action['url'], $action['htmlOptions']) : BHtml::button($action['text'], $action['htmlOptions']); } echo BHtml::tag('div', array('class' => 'modal-footer'), implode("\n", $actions)); } echo BHtml::closeTag('div'); // container BHtml::registerBootstrapJs(); }
/** * Displays the first validation error for a model attribute. * This is similar to {@link BHtml::error} except that it registers the model attribute * so that if its value is changed by users, an AJAX validation may be triggered. * @param CModel $model the data model * @param string $attribute the attribute name * @param array $htmlOptions additional HTML attributes to be rendered in the container div tag. * Besides all those options available in {@link BHtml::error}, the following options are recognized in addition: * <ul> * <li>validationDelay</li> * <li>validateOnChange</li> * <li>validateOnType</li> * <li>hideErrorMessage</li> * <li>inputContainer</li> * <li>errorCssClass</li> * <li>successCssClass</li> * <li>validatingCssClass</li> * <li>beforeValidateAttribute</li> * <li>afterValidateAttribute</li> * </ul> * These options override the corresponding options as declared in {@link options} for this * particular model attribute. For more details about these options, please refer to {@link clientOptions}. * Note that these options are only used when {@link enableAjaxValidation} or {@link enableClientValidation} * is set true. * * When client-side validation is enabled, an option named "clientValidation" is also recognized. * This option should take a piece of JavaScript code to perform client-side validation. In the code, * the variables are predefined: * <ul> * <li>value: the current input value associated with this attribute.</li> * <li>messages: an array that may be appended with new error messages for the attribute.</li> * <li>attribute: a data structure keeping all client-side options for the attribute</li> * </ul> * @param boolean $enableAjaxValidation whether to enable AJAX validation for the specified attribute. * Note that in order to enable AJAX validation, both {@link enableAjaxValidation} and this parameter * must be true. * @param boolean $enableClientValidation whether to enable client-side validation for the specified attribute. * Note that in order to enable client-side validation, both {@link enableClientValidation} and this parameter * must be true. This parameter has been available since version 1.1.7. * @return string the validation result (error display or success message). * @see BHtml::error */ public function error($model, $attribute, $htmlOptions = array(), $enableAjaxValidation = true, $enableClientValidation = true) { if (!$this->enableAjaxValidation) { $enableAjaxValidation = false; } if (!$this->enableClientValidation) { $enableClientValidation = false; } if (!isset($htmlOptions['class'])) { $htmlOptions['class'] = $this->errorMessageCssClass; } if (!$enableAjaxValidation && !$enableClientValidation) { return BHtml::error($model, $attribute, $htmlOptions); } $id = BHtml::activeId($model, $attribute); $inputID = isset($htmlOptions['inputID']) ? $htmlOptions['inputID'] : $id; unset($htmlOptions['inputID']); if (!isset($htmlOptions['id'])) { $htmlOptions['id'] = $inputID . '_em_'; } $option = array('id' => $id, 'inputID' => $inputID, 'errorID' => $htmlOptions['id'], 'model' => get_class($model), 'name' => BHtml::resolveName($model, $attribute), 'enableAjaxValidation' => $enableAjaxValidation); $optionNames = array('validationDelay', 'validateOnChange', 'validateOnType', 'hideErrorMessage', 'inputContainer', 'errorCssClass', 'successCssClass', 'validatingCssClass', 'beforeValidateAttribute', 'afterValidateAttribute'); foreach ($optionNames as $name) { if (isset($htmlOptions[$name])) { $option[$name] = $htmlOptions[$name]; unset($htmlOptions[$name]); } } if ($model instanceof CActiveRecord && !$model->isNewRecord) { $option['status'] = 1; } if ($enableClientValidation) { $validators = isset($htmlOptions['clientValidation']) ? array($htmlOptions['clientValidation']) : array(); foreach ($model->getValidators($attribute) as $validator) { if ($enableClientValidation && $validator->enableClientValidation) { if (($js = $validator->clientValidateAttribute($model, $attribute)) != '') { $validators[] = $js; } } } if ($validators !== array()) { $option['clientValidation'] = "js:function(value, messages, attribute) {\n" . implode("\n", $validators) . "\n}"; } } $html = BHtml::error($model, $attribute, $htmlOptions); if ($html === '') { if (isset($htmlOptions['style'])) { $htmlOptions['style'] = rtrim($htmlOptions['style'], ';') . ';display:none'; } else { $htmlOptions['style'] = 'display:none'; } $html = BHtml::tag('span', $htmlOptions, ''); } $this->attributes[$inputID] = $option; return $html; }