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}}
],
Related
By default you can add custom fields to several entities, however I don’t see the order entity in the list of available entities.
Is it possible to add such a field for order so user can fill it in the checkout process, right before sending the order?
And is it possible to add a field for the order and for each order item individually?
Here is one example on how to add to add custom fields to order entity:
$customFieldSetRepository = $this->container->get('custom_field_set.repository');
$customFieldSetRepository->upsert([
[
'name' => self::FIELD_NAME,
// 'global' => true,
'config' => [
'label' => [
'de-DE' => 'Name',
'en-GB' => 'Name'
]
],
'customFields' => [
[
'name' => 'name',
'type' => CustomFieldTypes::DATETIME,
'config' => [
'type' => 'date',
'dateType' => 'date',
'label' => [
'de-DE' => 'Date',
'en-GB' => 'Date'
]
]
],
[
'name' => 'name',
'label' => "Time",
'type' => CustomFieldTypes::TEXT,
'config' => [
'label' => [
'de-DE' => 'name',
'en-GB' => 'name'
]
]
],
[
'name' => 'name',
'label' => "name",
'type' => CustomFieldTypes::INT,
'config' => [
'label' => [
'de-DE' => 'name',
'en-GB' => 'name'
]
]
]
],
'relations' => [[
'entityName' => 'order'
]],
]
], $context);
i want to change the type of car_engine from text to option but i do not even understand what this code means and in which language i shall write my modification.
i have tried no thing because i had no idea where should i start.
public static function front_fields( $fields ) {
$fields[] = [
'forms' => ['car', ],
'type' => 'fieldset',
'id' => 'car',
'legend' => esc_html__( 'Car', 'listing-manager' ),
'collapsible' => true,
'fields' => [
[
'id' => LISTING_MANAGER_LISTING_PREFIX . 'car_engine',
'type' => 'text',
'label' => esc_html__( 'Engine', 'listing-manager' ),
'required' => false,
],
Try to use this way (untested):
public static function front_fields( $fields ) {
$fields[] = [
'forms' => ['car', ],
'type' => 'fieldset',
'id' => 'car',
'legend' => esc_html__( 'Car', 'listing-manager' ),
'collapsible' => true,
'fields' => [
[
'id' => LISTING_MANAGER_LISTING_PREFIX . 'car_engine',
'type' => 'select',
'label' => esc_html__( 'Engine', 'listing-manager' ),
'required' => false,
'options' => [ //options may be values
'alabama' => 'Alabama',
'alaska' => 'Alaska'
],
'placeholder' => '',
],
]
);
I need to include a conditional statement into the following array called $fields.
$fields = [
'program_id' => [
'type' => 'select',
'label' => 'Program',
'opts' => ["One", "Two", "Three"],
],
'name' => [
'label' => 'Job Name'
],
'start_date' => [
'class' => 'date-picker',
'label' => 'Job Starts' . $req,
'val' => $job->start_date ? dateToPicker($job->start_date) : null
],
'end_date' => [
'class' => 'date-picker',
'label' => 'Job Ends' . $req,
'val' => $job->end_date ? dateToPicker($job->end_date) : null
],
'section' => [
'type' => 'hidden',
'val' => 'details'
],
];
if (!$job->id && $program)
{
$fields['job_copy'] = [
'label' => 'Copy Job From',
'type' => 'select',
'textAsValue' => false,
'_comment' => 'Selecting a job here will copy all job information except the name.',
'opts' => array_replace([0 => '-- Select Job --'], $program->jobs()->lists('name', 'id')->all())
];
}
$fields[] = [
'type' => 'submit',
'label' => "Save",
'class' => 'btn btn-primary !important'
];
}
I need to move the conditional statement to the top so that it is the first thing displayed on the form. However, when I move it to the top it disappears. How can I integrate the conditional check into the top of the form as opposed to at the bottom where it currently displays?
$fields = [];
if (!$job->id && $program)
{
$fields['job_copy'] = [
'label' => 'Copy Job From',
'type' => 'select',
'textAsValue' => false,
'_comment' => 'Selecting a job here will copy all job information except the name.',
'opts' => array_replace([0 => '-- Select Job --'], $program->jobs()->lists('name', 'id')->all())
];
}
$fields2 = [
'program_id' => [
'type' => 'select',
'label' => 'Program',
'opts' => ["One", "Two", "Three"],
],
'name' => [
'label' => 'Job Name'
],
'start_date' => [
'class' => 'date-picker',
'label' => 'Job Starts' . $req,
'val' => $job->start_date ? dateToPicker($job->start_date) : null
],
'end_date' => [
'class' => 'date-picker',
'label' => 'Job Ends' . $req,
'val' => $job->end_date ? dateToPicker($job->end_date) : null
],
'section' => [
'type' => 'hidden',
'val' => 'details'
],
];
$fields = array_merge($fields,$fields2);
$fields[] = [
'type' => 'submit',
'label' => "Save",
'class' => 'btn btn-primary !important'
];
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);
I'm trying to add a mass action to Customer grid to set a customer group (which will simulate subgroups) but the group assignment will have a limited time period.
I'm using Magento ver. 1.4.2.0.
In Customer grid definiton (in my class which extends Mage_Adminhtml_Block_Customer_Grid) I'm adding mass action like this:
/*...*/
$this->getMassactionBlock()->addItem('set_subgroup', array(
'label' => Mage::helper('customersubgroup')->__('Set Customer Subgroup'),
'url' => $this->getUrl('adminhtml/customersubgroup/massSetSubgroup'),
'additional' => array(
'subgroup' => array(
'name' => 'subgroup',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('customer')->__('Group'),
'values' => $subgroups
),
'valid_from' => array(
'name' => 'valid_from',
'type' => 'date',
'class' => 'required-entry',
'label' => Mage::helper('customersubgroup')->__('Valid From'),
'gmtoffset' => true,
'format' => '%d.%m.%Y'
),
'valid_to' => array(
'name' => 'valid_to',
'type' => 'date',
'class' => 'required-entry',
'label' => Mage::helper('customersubgroup')->__('Valid To'),
'gmtoffset' => true,
'format' => '%d.%m.%Y'
)
)
));
/*...*/
There should be a customer group selectbox and two date fields as additional parameters of this mass action.
The date fields are rendered as text inputs but without a datepicker functionality (no calendar icon). Is it possible to add this functionality somehow?
Thanks in advance.
I should probably shoot myself to the head right now. I've forgotten the image property in item definition:
/*...*/
$this->getMassactionBlock()->addItem('set_subgroup', array(
'label' => Mage::helper('customersubgroup')->__('Set Customer Subgroup'),
'url' => $this->getUrl('adminhtml/customersubgroup/massSetSubgroup'),
'additional' => array(
'subgroup' => array(
'name' => 'subgroup',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('customer')->__('Group'),
'values' => $subgroups
),
'valid_from' => array(
'name' => 'valid_from',
'type' => 'date',
'class' => 'required-entry',
'label' => Mage::helper('customersubgroup')->__('Valid From'),
'gmtoffset' => true,
'image' => '/skin/adminhtml/default/default/images/grid-cal.gif',
'format' => '%d.%m.%Y'
),
'valid_to' => array(
'name' => 'valid_to',
'type' => 'date',
'class' => 'required-entry',
'label' => Mage::helper('customersubgroup')->__('Valid To'),
'gmtoffset' => true,
'image' => '/skin/adminhtml/default/default/images/grid-cal.gif',
'format' => '%d.%m.%Y'
)
)
));
/*...*/
So YES, it is possible.