Symfony forms entity/document sorting the property - sorting

I'm using the symfony forms for creating a select-box with all my users.
I display them by fullname, but want to sort them alphabetically.
$builder->add('transferTo', 'document', [
'class' => 'UserBundle:User',
'property' => 'fullname',
'label' => 'Overdragen aan',
'attr' => ['class' => 'form-control selectpicker'],
'label_attr' => ['class' => 'col-sm-2 control-label'],
'multiple' => false,
'required' => true
]);
How can i sort the users alphabetically on fullname of firstName?

What you need is to add queryBuilder to the form params
use Doctrine\ORM\EntityRepository;
$builder->add('transferTo', 'document', [
'class' => 'UserBundle:User',
'query_builder' => function(EntityRepository $repository) {
return $repository->createQueryBuilder('u')->orderBy('u.fullname', 'ASC');
}
'property' => 'fullname',
'label' => 'Overdragen aan',
'attr' => ['class' => 'form-control selectpicker'],
'label_attr' => ['class' => 'col-sm-2 control-label'],
'multiple' => false,
'required' => true
]);
I assumed the fieldname in your entity is u.fullname

Related

How to reinitialize Html Builder in yajra datatable - laravel controller

I am using yjra datatable and html builder plugin. i want to show two datatable in one view. i am getting error like can not reinitialize
Controller :
public function edit($id ,Builder $builder){
$this->htmlBuilder->ajax(route('backend.ajax.my_peoples', ['project_id'=> $project->project_id,'request' => 'ajax_listing']));
$people_html = $this->htmlBuilder->columns([
['data' => 'project_person_role', 'name' => 'project_person_role', 'title' => 'Person Role'],
['data' => 'project_person_sort', 'name' => 'project_person_sort', 'title' => 'Sort'],
['data' => 'project_person_status', 'name' => 'project_person_status', 'title' => 'Status'],
['data' => 'action', 'name' => 'action', 'title' => 'Action', 'orderable' => false, 'searchable' => false, 'width' => '10%'],
]);
$this->htmlBuilder->ajax(route('backend.ajax.my_consultants', ['project_id'=> $project->project_id,'request' => 'ajax_listing']));
$dt_html = $this->htmlBuilder->columns([
['data' => 'project_consultant_role', 'name' => 'project_consultant_role', 'title' => 'Consultant Role'],
['data' => 'project_consultant_sort', 'name' => 'project_consultant_sort', 'title' => 'Sort'],
['data' => 'project_consultant_status', 'name' => 'project_consultant_status', 'title' => 'Status'],
['data' => 'action', 'name' => 'action', 'title' => 'Action', 'width' => '5%', 'orderable' => false, 'searchable' => false]
]);
return view('backend.projects.projects')->with([
'view_type' => 'edit',
'view_title' => 'Update',
'cslt_html' => $dt_html,
'people_html' => $people_html
]);
}

Codeigniter 3 validation rule

i have a problem with form validation rule:
This is controller:
$this->load->library('form_validation');
$vL = array(
array(
"field" => $this->input->post('username'),
"rules" => "trim|required",
'errors' => array(
'required' => 'You must provide a %s.',
),
),
array(
"field" => $this->input->post('password'),
"rules" => "trim|required",
'errors' => array(
'required' => 'You must provide a %s.',
),
)
);
$this->form_validation->set_rules($vL);
if ($this->form_validation->run()) {
print "ok";
} else {
print "not ok"<br /><br />";
}
View login:
echo form_open('', ['action' => '', 'id' => 'frmUsers', 'autocomplete' => 'off', 'class' => 'form-signin']);
echo form_input(['name' => 'username', 'class' => 'form-control', 'placeholder' => 'username', 'required' => 'required']);
echo form_input(['name' => 'password', 'class' => 'form-control', 'type' => 'password', 'required' => 'required']);
$data = array(
"type" => "submit",
"name" => "login",
"value" => "Sign in",
"class" => "btn btn-lg btn-primary btn-block",
);
echo form_submit($data);
I don't know where is the problem.Maybe because i don't have a label, but i'm not sure.Thank you !
in the form validation array the "field" is for the name of the input not for it's value so "field" => "username" and "field" => "password" etc.

Prestashop 1.7 custom field

I have added 'credit_impot' custom field to my prestashop 1.7. It works but I can't update the custom field.
here is my codes
Product.php
public $credit_impot;
...
'fields' => array(
'credit_impot' => array('type' => self::TYPE_STRING),
\src\PrestaShopBundle\Form\Admin\Product\ProductPrice.php
$builder->add('credit_impot', 'Symfony\Component\Form\Extension\Core\Type\TextType', array(
'required' => false,
'attr' => ['placeholder' => $this->translator->trans('Andrana', [], 'Admin.Catalog.Help')]
));
\src\PrestaShopBundle\Model\Product\AdminModelAdapter.php
['step2' => ['credit_impot' => $this->product->credit_impot, ...
\src\PrestaShopBundle\Resources\views\Admin\Product\form.html.twig
{{ form_widget(form.step2.credit_impot) }}

set selected field when define with 'type' => 'select' in magento

I have a custom module where I create a form.
One field is a dropdown with values from a flat file.
$fields = array(
'type_of_service' => array('display' => 'Tip serviciu',
'required' => true,
'type' => 'select',
'options' => $serviceTypeOptions,
How can I set one value to be selected ?
EDIT:
if I use something like this in _prepareForm()
$fieldset->addField('select', 'select', array(
'label' => Mage::helper('tracking')->__('Select'),
'class' => 'required-entry',
'required' => true,
'name' => 'title',
'value' => '3',
'values' => array('-1'=>'Please Select..','1' => 'Option1','2' => 'Option2', '3' => 'Option3'),
)),
preselected will be 3.
But I generate my fields previously, and assign those to form with
$formFields = $this->getFormFields();
The problem is that I can't use the addField method, I need to have them created within my function.
Thanks.
try this,
'required' => true,
'value' => '2',
'values' => array(
array('1' => 'Option 1','2' => 'Option 2'),
...
which will select Option 2.
Try this
'required' => true,
'value' => 2,
'values' => array(
array('label' => 'Option 2', value => 2),
array('label' => 'Option 1', value => 1)
)
A full example can be like below
$fieldset->addField(
'target_type',
'select',
array(
'label' => $this->__("Target Type"),
'class' => 'required-entry',
'required' => 'true',
'name' => 'target_type',
'note' => $this->__("Target Type"),
'value' => 2,
'values' => array(
array(
'value' => 2,
'label' => 'Option 2'
)
)
)
);
NOTE : If you want to know about any of the Varien_Data_Form_Elements, you can directly do an inspection of Varien library /lib/Varien/Data/Form/Element/Select.php in your case.

Magento EAV: What is the 'source' setting used for?

I'm curious what this is used for? I defined the following source model for a custom attribute I added with an entity script, yet I have no idea how to make use of the source attribute. Maybe I can use it a Form Widget? The attribute I added was exportStatus to customer eav.
<?php
class Company_Customer_Model_Customer_Attribute_Source_ExportStatus
extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
public function getAllOptions()
{
if (!$this->_options) {
$this->_options = array(
array(
'value' => '0',
'label' => 'Pending Export',
),
array(
'value' => '1',
'label' => 'Exported to Mainframe',
),
array(
'value' => '2',
'label' => 'Acknowledged by Mainframe',
)
);
}
return $this->_options;
}
}
and
<?php
class Company_Customer_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
{
public function getDefaultEntities()
{
return array(
'customer' => array(
'entity_model' =>'customer/customer',
'attribute_model' => 'customer/attribute',
'table' => 'customer/entity',
'additional_attribute_table' => 'customer/eav_attribute',
'entity_attribute_collection' => 'customer/attribute_collection',
'attributes' => array(
'export_status' => array(
//'group' => 'Group/Tab',
'label' => 'Customer Export Status',
'type' => 'int',
'input' => 'select',
'default' => '0',
'class' => '',
'backend' => '',
'frontend' => '',
'source' => 'company_customer/customer_attribute_source_exportStatus',
'global' => 2, //global scope
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => false,
'visible_in_advanced_search' => false,
'unique' => false
)
)
)
);
}
}
It allows you to create drop down menus.
See this article:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/installing_custom_attributes_with_your_module
Specifically Appendix A: Dropdown Options

Resources