Yii2 Editable Widget custom attribute - php

i am working with Yii2 and using Editable Widget
My code is below
Editable::widget([
'id' => 1,
'name' => 'assignTo',
'value' => 1,
'url' => 'url here',
'type' => 'select',
'mode' => 'inline',
'clientOptions' => [
'toggle' => 'dblclick',
'emptytext' => 'Unassigned',
'placement' => 'right',
'select2' => [
'width' => '124px'
],
'source' => 1,
'value' => 1,
],
]);
i want to add custom attribute on that generated html tag. i have tried as below but its throw error
Editable::widget([
'id' => 'assignTo_'.$todo->id,
'name' => 'assignTo',
'redirect_url' => 'custom_attriute', // this is custom attribute that i need
'class' => 'my own custom class', // this is custom attribute that i need
'value' => 1,
'url' => 'url here',
'type' => 'select',
'mode' => 'inline',
'clientOptions' => [
'toggle' => 'dblclick',
'emptytext' => 'Unassigned',
'placement' => 'right',
'select2' => [
'width' => '124px'
],
'source' => 1,
'value' => 1,
],
]);
and also i want to add my own class in the generated html i have tried same as above but its not working.
is there any way to make it possible what i want?

dosamigos\editable\Editable extends yii\widgets\InputWidget which has an $options variable that holds:
The HTML attributes for the input tag.
Editable::widget([
'id' => 'assignTo_'.$todo->id,
'name' => 'assignTo',
'options' => [
'redirect_url' => 'custom_attriute', // this is custom attribute that i need
'class' => 'my own custom class', // this is custom attribute that i need
],
'value' => 1,
'url' => 'url here',
'type' => 'select',
'mode' => 'inline',
'clientOptions' => [
'toggle' => 'dblclick',
'emptytext' => 'Unassigned',
'placement' => 'right',
'select2' => [
'width' => '124px'
],
'source' => 1,
'value' => 1,
],
]);

Related

Notice: Undefined index: content in onboarding.php on line 43

I'm getting this error and not sure why. Here's my code :
$genesis_sample_shared_content = genesis_get_config( 'onboarding-shared' );
return [
'starter_packs' => [
'black-white' => [
'title' => __( 'Black & White', 'genesis-sample' ),
'description' => __( 'A pack with a homepage designed with black and white images.', 'genesis-sample' ),
'thumbnail' => get_stylesheet_directory_uri() . '/config/import/images/thumbnails/home-black-white.jpg',
'demo_url' => 'https://demo.studiopress.com/genesis-sample/',
'config' => [
'dependencies' => [
'plugins' => $genesis_sample_shared_content['plugins'],
],
'content' => array_merge(
[
'homepage' => [
'post_title' => 'Homepage',
'post_content' => require dirname( __FILE__ ) . '/import/content/home-black-white.php',
'post_type' => 'page',
'post_status' => 'publish',
'comment_status' => 'closed',
'ping_status' => 'closed',
'meta_input' => [
'_genesis_layout' => 'full-width-content',
'_genesis_hide_title' => true,
'_genesis_hide_breadcrumbs' => true,
'_genesis_hide_singular_image' => true,
],
],
],
$genesis_sample_shared_content['content']
),
'navigation_menus' => $genesis_sample_shared_content['navigation_menus'],
'widgets' => $genesis_sample_shared_content['widgets'],
],
],
],
];
I have modified the onboarding-shared.php file and remove the code for the content Maybe this is the problem?
Update : Now the menu items are created on theme setup. Here's the modified code :
return [
'plugins' => [
[
'name' => __( 'Genesis Blocks', 'genesis-sample' ),
'slug' => 'genesis-blocks/genesis-blocks.php',
'public_url' => 'https://wordpress.org/plugins/genesis-blocks/',
],
],
'navigation_menus' => [
'primary' => [
'get-started' => [
'title' => 'Get Started',
],
'testimonials' => [
'title' => 'Testimonials',
],
'contact' => [
'title' => 'Contact Us',
],
],
],
'widgets' => [
'footer-1' => [
[
'type' => 'text',
'args' => [
'title' => 'Design',
'text' => '<p>With an emphasis on typography, white space, and mobile-optimized design, your website will look absolutely breathtaking.</p><p>Learn more about design.</p>',
'filter' => 1,
'visual' => 1,
],
],
],
'footer-2' => [
[
'type' => 'text',
'args' => [
'title' => 'Content',
'text' => '<p>Our team will teach you the art of writing audience-focused content that will help you achieve the success you truly deserve.</p><p>Learn more about content.</p>',
'filter' => 1,
'visual' => 1,
],
],
],
'footer-3' => [
[
'type' => 'text',
'args' => [
'title' => 'Strategy',
'text' => '<p>We help creative entrepreneurs build their digital business by focusing on three key elements of a successful online platform.</p><p>Learn more about strategy.</p>',
'filter' => 1,
'visual' => 1,
],
],
],
],
];
The menu items aren't for pages, they're linked to scroll points on the homepage. Not sure how to code that using the above PHP?
I removed $genesis_sample_shared_content['content'] and it now works except the menu items aren't created on theme setup maybe due to this error
Notice: Trying to get property 'name' of non-object in wp-admin/nav-menus.php on line 1098

The 'pluginOptions["url"]' property has not been set

I have a problem with Kartik/DepDrop. I have used it many times in the past but are now having an issue
My view
'contentBefore'=>'<legend class="text-info"><small>Client Info</small></legend>',
'attributes'=>[ // 2 column layout
'model'=>['type'=>Form::INPUT_DROPDOWN_LIST, 'items'=>ArrayHelper::map(\app\models\Models::find()->All(), 'id','name'), 'options'=>['prompt'=>'Please Select..','id'=>'model']],
'field'=>[
'type'=>Form::INPUT_WIDGET,
'widgetClass'=>DepDrop::classname(),
'options' => ['id'=>'field'],
'pluginOptions' => [
'depends' => ['model'],
'placeholder' => 'select ...',
'url' => Url::to(['dd-field'])
],
],
'related_value'=>['type'=>Form::INPUT_TEXT, 'options'=>['placeholder'=>'Enter Value...']],
]
And the error shows this
_form.php at line 49 – yii\base\Widget::widget(['model' => app\models\RelatedFields, 'form' => kartik\form\ActiveForm, 'autoGenerateColumns' => true, 'rows' => [['contentBefore' => '<legend class="text-info"><small...', 'attributes' => ['model' => ['type' => 'dropdownList', 'items' => [1 => 'Clients', 2 => 'InvoiceItems', 3 => 'Invoices', 4 => 'Notes', ...], 'options' => ['prompt' => 'Please Select..', 'id' => 'model']], 'field' => ['type' => 'widget', 'widgetClass' => 'kartik\depdrop\DepDrop', 'options' => ['id' => 'field'], 'pluginOptions' => ['depends' => ['model'], 'placeholder' => 'select ...', 'url' => '/related-fields/dd-field']], 'related_value' => ['type' => 'textInput', 'options' => ['placeholder' => 'Enter Value...']]]], ['attributes' => ['actions' => ['type' => 'raw', 'value' => '<div style="text-align: right; m...']]]], ...])
If you look at the plugin options it is being passed
'pluginOptions' => ['depends' => ['model'], 'placeholder' => 'select ...', 'url' => '/related-fields/dd-field']
Any ideas anyone.
Found the issue, as i am using FormGrid, the pluginOptions and htmlOptions all need to be inside an options array like this
'field'=>[
'type'=>Form::INPUT_WIDGET,
'widgetClass'=>DepDrop::classname(),
'options' => [
'options'=> ['id' => 'field'],
'pluginOptions' => [
'depends' => ['model'],
'placeholder' => 'select ...',
'url' => '/related-fields/dd-field'
],
],
],

Preselecting an option from a select field in a fields array?

Observe the following $fields array, which is used as an input form in a blade:
$fields = [
'user_id' => [
'label' => 'Opportunity Owner' . $req,
'type' => 'select',
'class' => 'select2',
'opts' => User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()
],
'name' => [
'label' => 'Opportunity Name' . $req,
],
'agent_id' => [
'label' => 'Agent',
'type' => 'select',
'class' => 'select2',
'textAsValue' => false,
'opts' => array_replace([0 => '-- Select Sales Rep --'],
User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()),
],
'description' => [
'label' => 'Description',
'type' => 'textarea'
],
[
'type' => 'submit',
'label' => 'Save',
'class' => 'btn btn-primary !important'
]
];
In the 'agent_id' part, I'd like to pre-select a value if the user has a value preassigned. I know how to get the info from the user, but I am lost as to how to 'select' an option in the array within the 'agent_id' field. I need all options to show in the select, but I want to be able to have one 'selected' based on the agent_id number linked to the user. I tried the following:
'agent_id' => [
'label' => 'Agent',
'type' => 'select',
'class' => 'select2',
'textAsValue' => false,
'opts' => array_replace([0 => '-- Select Sales Rep --'],
User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()),
'selected' => {{appropriate number here}}
],
But that did not work. How could I go about doing this?
Add selected value without any index.
Try this:
'agent_id' => [
'label' => 'Agent',
'type' => 'select',
'class' => 'select2',
'textAsValue' => false,
'opts' => array_replace([0 => '-- Select Sales Rep --'],
User::whereTenantId(tenant()->id)->whereRole('Admin')->get()->lists('name', 'id')->all()),
{{appropriate number here}}
],

Yiibooster editable widget inside popover widget

I'm building website using yii 1.1 framework and Clevertech YiiBooster extension.
Is there an easy way to render few "editable field" widgets inside the popover widget ?
Please see the code below. Any suggestions are welcome.
Main view:
....
$this->widget(
'booster.widgets.TbButton', array(
'label' => 'Right popover',
'context' => 'warning',
'buttonType' => 'button',
'size' => 'extra_small',
'htmlOptions' => array(
'id' => uniqid(),
'data-html' => true,
'data-title' => 'A Title',
'data-placement' => 'right',
'data-content' => $this->renderPartial('VIEW', array('data'=>$data), true, true),
'data-toggle' => 'popover'
),
)
);
....
partial view:
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);
$this->widget('booster.widgets.TbEditableField', array(
'type' => 'text',
'model' => $survey,
'attribute' => 'text',
'pk' => 'pk',
'name' => 'name',
'text' => '',
'url' => $this->createUrl('controller/method/'), //url for submit data
'title' => 'text',
'placement' => 'right',
'id' => uniqid()),true);

Yii2 how to set the title for the widget ListView

I have installed in Yii 1.1
$this->widget('zii.widgets.CListView', array(
'template' => Yii::t('Site','Header News')
But how 'to do it in Yii2 ?
echo ListView::widget(['template' => Yii::t('Site','Header News'),
'dataProvider' => $tipsList,
'itemView' => '_listItem',
'layout' => '{items}{pager}',
'itemOptions' => [
],
'options' => [
'links' => '<h2>test</h2>',
'tag' => 'ul',
'class' => 'ten-vertical summary-list',
],
'viewParams' => array(
'categoryAlias' => $categories[0]->urlAlias,
'imageConfig' => array('width' => 120, 'height' => 120, 'fill' => true),
'firstImageConfig' => array('width' => 436, 'height' => 436, 'fill' => true),
),
]);
Param 'template' => Yii::t('Site','Header News') does not work
template property of ListView in Yii2 called layout. Link
Example:
'layout' => '<li class="list-header">Header</li>{items}{pager}',
'options' => [
'tag' => 'ul',
],
The li.list-header will be added into a parent tag ul

Categories