I'm trying to use the select2entity-bundle for my project to implement auto-complete.
When using the builder, the specification is as follows :
$builder
->add('country', Select2EntityType::class, [
'multiple' => true,
'remote_route' => 'tetranz_test_default_countryquery',
'class' => '\Tetranz\TestBundle\Entity\Country',
'primary_key' => 'id',
'text_property' => 'name',
'minimum_input_length' => 2,
'page_limit' => 10,
'allow_clear' => true,
'delay' => 250,
'cache' => true,
'cache_timeout' => 60000, // if 'cache' is true
'language' => 'en',
'placeholder' => 'Select a country',
// 'object_manager' => $objectManager, // inject a custom object / entity manager
])
What should be specified within the 'remote_route' parameter?
Why should my field be linked to a route? How and where should this route be configured? Should it be linked to a query?
Thanks for your help!
The select needs to update the values to display while he user is typing. It does this by sending a request to a controller you need to write, which collects the relevant values and returns them as json.
Create a controller that returns the list of items to display in the select, and use the name of the route you defined for that controller as the 'remote_route' parameter.
The format for the returned data is documented halfway down the page for the bundle on github https://github.com/tetranz/select2entity-bundle
Related
I was wondering if there is a way to make the tristate version of SwitchInput widget as a filter for a bool column in a GridView?
It’s rendering correctly but it’s not updating on change (Select2 does though).
[
'attribute' => 'enabled',
'format' => 'boolean',
'filter' => SwitchInput::widget([
'name' => 'DeviceSearch[enabled]',
'options' => [
'class' => 'form-control'
],
'value' => $searchModel->enabled,
'tristate' => true
])
]
Last column:
If you use GridView from Kartik it lets extend the base colum to add filterType, so:
[
'attribute' => 'enabled',
'format' => 'boolean',
'filterType' => GridView::FILTER_SWITCH,
]
Will generate an SwitchInput widget as a filter on top, you need to configurate the rest of parameters, or at least the required ones for the switch input filter type.
I am trying to display a field in editview alone based on a fieldvale in userdetails.
Ex: For an user can_add_no will be in user details, if it is checked than that particular user can add a quote_extra_no in quote module.
I tried the following. Added dependency for the quote module for the field.
$dictionary['Quote']['fields']['quote_extra_no'] = array (
'audited' => true,
'calculated' => false,
'duplicate_merge' => 'disabled',
'duplicate_merge_dom_value' => '0',
'importable' => 'true',
'len' => '255',
'massupdate' => false,
'merge_filter' => 'disabled',
'name' => 'quote_extra_no',
'no_default' => true,
'reportable' => true,
'required' => false,
'size' => '50',
'source' => 'custom_fields',
'studio' => 'visible',
'type' => 'varchar',
'unified_search' => false,
'vname' => 'LBL_EXTRA_REF',
'dependency' => 'equal(related($assigned_user_link,"can_add_no"),"1")',
);
Also added the field in Editview. But its not working. If the current user can_add_no is set or checkbox is ticked. He can Edit the quote_extra_no in the editview of the quote.
How can i achive the functionality as the dependency is not helping me to do it.
There are two may to do that for both way you should have relation between both module.
By Using Dependency :
equal(related($related_field_name,"can_add_no"),"1")'
IN record.js write a method in that method call a api for canadd_no and according to that show hide the field.
API call Example :
app.api.call('read', app.api.buildURL(this.model.get('_module'), 'read', {id: this.model.get('id')}), null,
{
success: function(data) {
your costume code to hide
}
},
});
More Info related to API
I`ve got a dropdown list in my Symfony2 form like this:
$builder->add('categories','entity', array(
'class' => 'MyBundle:Myentity',
'property' => 'name',
'label' => 'Mylabel',
'expanded' => false,
'multiple' => false,
'label_attr' => array ( 'class' => 'control-label' ),
'attr' => array ( 'class' => 'form-control',
'placeholder' => 'Placeholder',
'title' => "Mytitle",
'data-toggle' => 'tooltip',
'data-myidfromDB' => '????',
'data-mynamefromDB'=>'????' etc. )));
So I am getting a list of MyBundle:Myentity objects and when I choose one I want to show all its properties (like ID, name, etc.) which are stored in my DB and described in Entity class, in different html data-* fields. If I select another one from the list I want to see all information related to my newly selected option in HTML (to change dynamically). Any ideas how to do that?
Since Symfony 2.7 you can set the option choice_attr to ChoiceType and set it a callable receiving the choice as an argument.
EntityType inherits this option and the choice in that case is the instantiated entity, so you can write something like :
$builder->add('categories','entity', array(
'class' => 'MyBundle:MyEntity',
'property' => 'name',
'label' => 'Mylabel',
'attr' => array('class' => 'form-control'),
'label_attr' => array('class' => 'control-label'),
'choice_attr' => function (\AppBundle\Entity\MyEntity $myEntity) {
return array(
'data-private-property' => $entity->getPrivateProperty(),
'data-some-value' => $entity->someMethod(),
);
},
);
You can't do that in easy way.
But you can put more information in select label.
Look on
http://symfony.com/doc/current/reference/forms/types/entity.html#choice-label
Yout can put here more field details and get it from your javascript.
I have a form with a field of relationship entity.
The problem is that that entity tien a lot of records, over 170,000 and render the view form the server is saturated and no load.
What solutions are there to this?
This is the form field
->add('stream', 'genemu_jqueryselect2_entity', array(
'class' => 'AcmeBundle:Stream',
'property' => 'name',
'choice_label' => 'name',
'multiple' => false,
'required' => false,
'configs' => array(
'multiple' => false,
)
)
)
IMPORTANT
I found something.
Stream entity is related to another entity under a bidirectional one-to-one.
Doctrine is running a query for each record to grab the data from that relationship.
Is there any way to tell Doctrine to not spread relationships and take "real" data Stream entity?
If I correctly understand you, you shoud look to query_builder options what allow you to fetch Streams what sutisfy some condition. E.g.:
->add('stream', 'genemu_jqueryselect2_entity', array(
'class' => 'AcmeBundle:Stream',
'property' => 'name',
'choice_label' => 'name',
'multiple' => false,
'required' => false,
'configs' => array(
'multiple' => false,
)
'query_builder' => function (StreamRepository $repository) {
return $repository->findStreamsWhatSatisfySomeCondition();
}
)
you can use external parameters like:
'query_builder' => function (StreamRepository $repository) use ($param) {
}
Detailed info you can find in doc. Hope that will help find solution :)
I've written a module that adds an attribute to the customer model, and it's worked fine.
I wanted to extend the sales/order_shipment model and add another attribute, so I just used the same reference that I had used for the installer for adding the new customer attribute.
I relied on Magento finding and installing the module a file with the following path and name app/code/local/[namespace]/[module_name]/sql/install-01.php
I've set the installer to the value of $this during the setup of the module initially:
$installer = $this;
$installer->startSetup();
I kept the same reference for the installer and just added a new field:
$installer->addAttribute('customer','sap_bp_id',
array(
'type' => 'varchar',
'label' => 'SAP Business One Business Partner ID',
'input' => 'text',
'required' => false,
'visible' => true,
'visible_on_front' => false,
'global' => 1,
'position' => 62,
)
);
$installer->addAttribute('shipment','sap_doc_num',
array(
'type' => 'varchar',
'label' => 'SAP Business One Document Number',
'input' => 'text',
'required' => false,
'visible' => true,
'visible_on_front' => false,
'global' => 1,
'position' => 62,
)
);
It's worked just fine, but I want to know this:
Is this the correct method for adding a new attribute for different models in the same installation file? Is there a better method? Have I missed anything?