Yii 2 Exclude NavBar in Modal - php

In my index.php view, I have a button, once clicked, a modal will pop up:
<p>
<?= Html::button(
'Create New BizAdmin',
['value' => Url::to(['createbizadmin']),
'class' => 'btn btn-success',
'id' => 'modalButton'
]) ?>
<?php
Modal::begin(['id' => 'modal']);
echo "<div id='modalContent'></div>";
Modal::end();
?>
</p>
My modal file is createbizadmin.php where it has the following codes:
<?php
use yii\helpers\Html;
/* #var $this yii\web\View */
/* #var $model app\models\User */
$this->title = 'Create New Bizadmin';
?>
<div class="user-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_formbizadmin', [
'model1' => $model1,
'model2' => $model2,
]) ?>
</div>
My problem is this:
As you can see, the navbar looks horrible. The menu list seems to overflow outside the modal.
How do I get rid of the navbar inside my modal? I can't seem to find which part of creatbizadmin.php I should edit.
Any thoughts?

I'm guessing that you have a controller somewhere that is handling the url createbizadmin. I'm also guessing that inside that controller action you are rendering the view file like this;
$this->render("createbizadmin");
If so, then that is your problem. By calling a view file directly, Yii will apply default layouts to the view file. You have no control over how this happens from within the called view file, and all your menus etc will be rendered.
To get around this you will probably need to render a partial file. This rendres the file without applying layouts. So use;
$this->renderPartial("createbizadmin")
Alternatively, if the modal content is being generated as a result of an ajax call, you can respond from the controller with;
$this->renderAjax("createbizadmin")
This article seems to have a good explanation of how best to achieve this; Render a form in a modal popup

Related

Why i'm Getting Call to a member function formName() on null in yii2

I can't find any supporting resources for the error Call to a member function formName() on null. The scenario of getting this error when opening a update page. I've checked the rendered variable on update page by print_r() and its fine.
Then I checked by removing the all input field which codes in yii2 ActiveFrom chtml
<?= $form->field($model, 'name')->textInput(['maxlength' => true, 'class' => ' form-control']) ?>
and kept some input fields which is in normal html syntax
<input type="text" class="qty" name="qty[]" value="1" style="width: 24px;" value="<?php echo $value->qty; ?>">
Then it worked.
Why this error occurred and how to fix it.
Thanks,
You are probably not passing an update model from controller's action to view. Make sure you pass the loaded model in your update action to view like this:
public function actionUpdate($id)
{
$model = $this->findModel($id);
//... other update action code
return $this->render('update', ['model' => $model]);
}
If you are using some common _form template that you include into your create/update templates you also have to make sure the $model is passed from your update template to the _form template.
<!-- ... your update template code ... -->
<?= $this->render('_form', ['model' => $model]); ?>
<!-- ... the rest of update template ... -->
Another option is that you are overwiriting the $model variable somewhere in your templates.

how to place yii2 form error in title of anchor tag

how to place yii2 form error in title of anchor tag
This is my code
$form = ActiveForm::begin([
'id' => 'login-form',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
'template' => '
{label}
<div class="error-block">
error
</div>
{input}
',
'errorOptions' => ['tag' => null]
],
]);
I want to add error in title of anchor tag in YII2
error
You need to display the error text inside the anchor tags title attribute, and using the template option wont help you achieve it automatically.
A few things in your approach.
You are specifying the "tag"=>null under the errorOptions which wont create the default html <p class="help-block help-block-error"></p>.
Even if you specify the tag as div or span even then it will break the HTML as the attribute title has double quotes error and the tag created will also have double quotes <div class="help-block help-block-error"></div>.
Then if you change the error to <a href="#" title=\'{error}\'>error</a> to fix the broken HTML the javascript wont be able to detect the element.
So then the event afterValidateAttribute will come to your rescue which is triggered after validating the whole form and each attribute.
The signature of the event handler should be:
function (event, attribute, messages)
where
event: an Event object.
attribute: the attribute being validated. Please refer to attributeDefaults for the structure of this parameter.
messages: an array to which you can add additional validation error messages for the specified attribute.
Now change the template under the fieldConfig to the following and remove the {error} from the template and the errorOptions, as it is not needed and just keep you custom error element inside the template.
'fieldConfig' => [
'template' => '
{label}
<div class="error-block">
error
</div>
{input}
',
],
Now add the below javascript at the top of your view where you are rendering the form.
$js = <<< JS
$("#login-form").on(
'afterValidateAttribute',
function (event,attribute,messages) {
let input=attribute.input;
$(input).siblings('.error-block').find('a').attr('title',messages.join(','));
}
);
JS;
$this->registerJs($js, \yii\web\View::POS_READY);
Now if you focus out of the fields or hit the submit button you will see the error messages being populated in the title attribute of the a tag.

OctoberCMS | access to static page property from component

There are some way to extract values from extra-fields of static pages into some component?
I need that to implement AJAX handlers...
I can load the static page content but, I need to get properties that was setted by user...
I need some example of code... I can load the static page content as a Partial
#noobhacks :)
public function onOpenHome()
{
$this->page['categories'] = Category::all();
return [
//'main' => $this->renderPartial('home'),
'main' => $this->renderPartial('../content/static-pages/index'),
'.home_categories' => $this->renderPartial('work_list_categories_post')
];
}
or as content:
[viewBag]
==
<main class="home_container" __color="{{ color }}">
<section class="box">
{% content '/static-pages/index.htm' %} <!-- <<<<------ -->
{{ content |raw }}
</section>
</main>
But I have no ideia how to access to property of colorpicker color
Component objects are available using their name (or alias). This means the value of "color" should be available via {{ viewBag.color }}.

how to edit clistview and cgridview with bootstrap3

I like to use bootstrap 3 with yii. I am stuck with how to edit CListview and CGridview and add in the neccesarry classes.
My code
$this->widget('zii.widgets.CListView',array(
'dataProvider'=>$dataProvider,
// refers to the partial view named '_thumb'
'itemView'=>'_thumb',
'template' => "{summary}{sorter}{pager}{items}{pager}",
'itemsCssClass' => 'nav row',
'pagerCssClass'=>'pagination', // doesn't work is set on <div> instead of <ul>
// 'sorterCssClass'=>'row-fluid', // how to so this...
)); ?>
I tried putting the 'pagination' class. but the class is splaced on the div tag instead of the ul tag that is required. With CGridview it is the same
I used the yii bootstrap extension but it doesn't work with bootstrap3 and I like to know how to do it the easy way.

Passing data from view to controller in yii

I have a text field in my view and I want to pass the value of textbox to the controller, but I don't know how to do it.
I have tried googling it but it only gives ides about passing data from conntroller to view in yii, so please give an example of doing this with ajax.
follow the steps:
in form:
<div class="form-group">
<?php echo $form->labelEx($model,'order_id', array('class' => 'control-label col-lg-4')); ?>
<div class="col-lg-8">
<?php echo $form->textField($model,'order_id',array('class' => 'form-control',
'ajax' =>
array('type'=>'POST',
'url'=>$this->createUrl('recieveValue'), // write in controller this action
'update'=>'#price',
'data'=>array('order_id'=>'js:this.value'),
)
)); ?>
</div>
<?php echo $form->error($model,'order_id'); ?>
In controller:
public function actionRecieveValue(){
echo $_POST['order_id'];
}
At the top of same controller:
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('create','update','recieveValue'),
'users'=>array('#'),
),
Explanation:
Here text field id is order_id, controller action is recieveValuewhat I wrote in the ajax URL as 'url'=>$this->createUrl('recieveValue'),. Go to the controller and write action name as actionRecieveValue just add action before recieveValue. Now go to the top of the controller in the method accessRules and allow it recieveValue into array. Now check through firebug console. Type something into the text box and move the mouse from the textbox. You will find that your textbox value will be recieved into the controller.

Categories