At first, example tables:
Products:
id
name
price
Promo:
product_id (to Products id foreign)
old_price
new_price
What type of field i should use to get a price from foreign item selected before?
price value to old_price
Field where i select a product:
$this->crud->addField([
'label' => 'Product',
'type' => 'select',
'name' => 'product_id',
'entity' => 'products',
'attribute' => 'name',
//'model' => "Backpack\Products\app\Models\Products",
]);
Promos model function:
public function products()
{
return $this->belongsTo(Products::class,'product_id','id');
}
I tried to use a select2_ajax but i got a route problem (error 404).
As a promo has at least one product you can say type relationship with the exact namespace of your model.
$this->crud->addField([
'label' => 'Product',
'type' => 'relationship',
'name' => 'product_id',
'entity' => 'products',
'attribute' => 'name',
'model' => 'Backpack\Products\app\Models\Products',
]);
Related
I have a roles field.
if (!is('admin')) {
$this->crud->removeField('roles_permissions');
}
I want a user with the admin role to have access to all options in this checklist field. However, a user with a client role should have access to these roles but only specific ones.
I tried this:
if (is('client')) {
$this->crud->addField([
'label' => ucFirst(__('Roles')),
'name' => 'roles',
'type' => 'checklist',
'model' => 'Backpack\PermissionManager\app\Models\Role',
'attribute' => 'name',
]);
}
But how do I limit the options coming from the model?
You should be able to pass all options to the checklist field by using the options attribute:
$this->crud->addField([
'label' => ucFirst(__('Roles')),
'name' => 'roles',
'type' => 'checklist',
'model' => 'Backpack\PermissionManager\app\Models\Role',
'attribute' => 'name',
'options' => [
1 => 'smth',
2 => 'smth else',
]
]);
I am working on Laravel Backpack. I have two fields like this:
$this->crud->addField([ // SELECT2
'label' => 'Type',
'type' => 'select_from_array',
'name' => 'type',
'options' => [
'' => 'select type',
'Movie' => 'Movies',
'Series' => 'Series'
],
]);
$this->crud->addField([ // select2_from_ajax: 1-n relationship
'label' => "Entity", // Table column heading
'type' => 'select2_from_ajax',
'name' => 'entity_id', // the column that contains the ID of that connected entity;
'entity' => 'entity', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'data_source' => url('api/entity'), // url to controller search function (with /{id} should return model)
'placeholder' => 'Select', // placeholder for the select
'include_all_form_fields' => true, //sends the other form fields along with the request so it can be filtered.
'minimum_input_length' => 0, // minimum characters to type before querying results
'dependencies' => ['type'], // when a dependency changes, this select2 is reset to null
// 'method' => 'GET', // optional - HTTP method to use for the AJAX call (GET, POST)
]);
The second field options are dependent on the first one.
In my model, I have:
public function getEntityIdAttribute()
{
$id = $this->attributes['entity_id'];
$type = $this->attributes['type'];
if ($type == "Movie") {
$attribute = Movie::find($id);
} else {
$attribute = Series::find($id);
}
return $attribute->name;
}
Create and List operations work perfectly. But on update, it throws this error:
Undefined array key "entity_id"
Why is this accessor not working on the update? or can we somehow skip the accessor on the update command?
I am using zendframework 2 and doctrine 2. I want to populate the values of my checkboxes from values in my database (dependence injection).
I got the technique from: https://github.com/doctrine/DoctrineModule/blob/master/docs/form-element.md
This is my element (it works for select elements but not for checkboxes):
$this->add(array(
'type' => 'Zend\Form\Element\MultiCheckbox',
'name' => 'timesId',
'options' => array(
'label' => 'Please Select Your Availablity',
'value_options' => array(
'object_manager' => $this->getObjectManager(),
'target_class' => 'FormDependencies\Entity\AvailablityTimeTableList',
'property' => 'job',
),
),
'attributes' => array(
'value' => '1' //set checked to '1'
)
));
public function getObjectManager()
{
return $this->objectManager;
}
I cannot find the native doctrine 2 method for checkboxes.
The error message:
Fatal error: Cannot use object of type Doctrine\ORM\EntityManager as array
i have resolved it;
under type i needed to specify that its a :
'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
the complete code:
$this->add(array(
'type' => 'DoctrineModule\Form\Element\ObjectMultiCheckbox',
'name' => 'timesId',
'options' => array(
'label' => 'Please Select Your Availablity',
'object_manager' => $this->getObjectManager(),
'target_class' => 'FormDependencies\Entity\AvailablityTimeTableList',
'property' => 'times',
'empty_option' => '--- please choose ---'
),
For example in Opportunities and Cases there are relationship fields directly pointing to accounts. I have a custom module that integrates into those modules. I could add a separate relate field for the custom module, but what I want is a flexrelate allowing only Accounts and the Custom module. This works fine by setting a special options list in the parent_name. but results in a parent_type and parent_id field in db.
How do I configure the flexrelate so that on selecting accounts as parent_type it save to account_id and on selecting the custom module it saves to it's id field?
The options for the flexrelate:
$app_list_strings['parent_type_display_custom']['CustomMod'] = 'CustomMod';
$app_list_strings['parent_type_display_custom']['Accounts'] = 'Accounts';
$app_list_strings['record_type_display_custom']['CustomMod'] = 'CustomMod';
$app_list_strings['record_type_display_custom']['Accounts'] = 'Accounts';
The additional vardefs for Cases:
$dictionary["Case"]["fields"]["parent_type"] = array (
'name' => 'parent_type',
'type' => 'link',
'vname' => 'LBL_PARENT_TYPE',
'type' => 'parent_type',
'dbType' => 'varchar',
'group' => 'parent_name',
'options' => 'parent_type_display_custom',
'len' => '255',
);
$dictionary["Case"]["fields"]['parent_name'] =
array(
'name' => 'parent_name',
'parent_type' => 'record_type_display',
'type_name' => 'parent_type',
'id_name' => 'parent_id',
'vname' => 'LBL_RELATED_TO',
'type' => 'parent(_custom)',
'source' => 'non-db',
'options' => 'record_type_display_custom',
);
$dictionary["Case"]["fields"]['parent_id'] =
array(
'name' => 'parent_id',
'vname' => 'LBL_PARENT_ID',
'type' => 'id',
'required' => false,
'reportable' => true,
'comment' => 'eighter the Id of an account or a custommodule'
);
Does this SugarCRM developer blog post help?
http://developers.sugarcrm.com/wordpress/2011/05/16/howto-create-a-flex-relate-for-other-modules/
how to get a value of selected item from select option In symfony?(from article below)
I have that config in my form:
$this->widgetSchema['category_id'] = new sfWidgetFormDoctrineChoice(array(
'model' => 'Category',
'method' => 'getLibelleCat',
'add_empty' => 'select category'
));
$this->widgetSchema['article_id'] = new sfWidgetFormDoctrineDependentSelect (array(
'model' => 'Article',
'method' => 'getLibelle',
'depends' => 'Category',
'add_empty' => 'select article'
));
Thanks
Hum... I'm not sure to understand the question, but I propose:
$this->getValue('category_id');